VCS_ImportExport.bas 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687
  1. Option Compare Database
  2. Option Explicit
  3. ' List of lookup tables that are part of the program rather than the
  4. ' data, to be exported with source code
  5. ' Set to "*" to export the contents of all tables
  6. 'Only used in ExportAllSource
  7. 'Private Const include_tables As String = ""
  8. Private include_tables As String
  9. ' This is used in ImportAllSource
  10. Private Const DebugOutput As Boolean = False
  11. 'this is used in ExportAllSource
  12. 'Causes the VCS_ and OA_ modules to be exported
  13. Private Const ArchiveMyself As Boolean = False
  14. 'returns true if named module is NOT part of the VCS / OA code
  15. Private Function IsNotVCS(ByVal name As String) As Boolean
  16. '*** if OA addin is used from its developement version (OA exporting itself)
  17. If CurrentProject.name = "openaccess.accda" Then
  18. IsNotVCS = True
  19. Exit Function
  20. End If
  21. '****
  22. If name <> "OA_Controls" And _
  23. name <> "OA_Log" And _
  24. name <> "OA_Main" And _
  25. name <> "OA_Optimizer" And _
  26. name <> "OA_Properties" And _
  27. name <> "OA_Shell" And _
  28. name <> "OA_Utils" And _
  29. name <> "VCS_DataMacro" And _
  30. name <> "VCS_Dir" And _
  31. name <> "VCS_File" And _
  32. name <> "VCS_IE_Functions" And _
  33. name <> "VCS_ImportExport" And _
  34. name <> "VCS_Reference" And _
  35. name <> "VCS_Relation" And _
  36. name <> "VCS_Report" And _
  37. name <> "VCS_String" And _
  38. name <> "VCS_Table" Then
  39. IsNotVCS = True
  40. Else
  41. IsNotVCS = False
  42. End If
  43. End Function
  44. ' Main entry point for EXPORT. Export all forms, reports, queries,
  45. ' macros, modules, and lookup tables to `source` folder under the
  46. ' database's folder.
  47. Public Sub ExportAllSource()
  48. Dim db As Object ' DAO.Database
  49. Dim source_path As String
  50. Dim obj_path As String
  51. Dim qry As Object ' DAO.QueryDef
  52. Dim doc As Object ' DAO.Document
  53. Dim obj_type As Variant
  54. Dim obj_type_split() As String
  55. Dim obj_type_label As String
  56. Dim obj_type_name As String
  57. Dim obj_type_num As Integer
  58. Dim obj_count As Integer
  59. Dim obj_data_count As Integer
  60. Dim ucs2 As Boolean
  61. Dim full_path As String
  62. logger "ExportAllSource", "INFO", "Begin 'Export all sources'"
  63. include_tables = get_include_tables()
  64. logger "ExportAllSource", "DEBUG", "Include_tables: " & include_tables
  65. logger "ExportAllSource", "DEBUG", "Optimizer on: " & optimizer_activated()
  66. logger "ExportAllSource", "DEBUG", "Save project"
  67. SaveProject
  68. Set db = CurrentDb
  69. CloseFormsReports
  70. 'InitUsingUcs2
  71. source_path = VCS_Dir.ProjectPath() & "source\"
  72. logger "ExportAllSource", "DEBUG", "source_path: " & source_path
  73. VCS_Dir.MkDirIfNotExist source_path
  74. Call ExportProperties(CurrentDb, source_path & "database.properties")
  75. obj_path = source_path & "queries\"
  76. VCS_Dir.ClearTextFilesFromDir obj_path, "bas"
  77. logger "ExportAllSource", "INFO", "Exporting queries..."
  78. obj_count = 0
  79. For Each qry In db.QueryDefs
  80. '### 11/10/2016: add optimizer
  81. If optimizer_activated() Then
  82. If Not needs_export(acQuery, qry.name) > 0 Then
  83. logger "ExportProperties", "DEBUG", "Query " & qry.name & " skipped"
  84. obj_count = obj_count + 1
  85. GoTo next_qry
  86. End If
  87. End If
  88. '###
  89. DoEvents
  90. If Left$(qry.name, 1) <> "~" Then
  91. full_path = obj_path & VCS_IE_Functions.to_filename(qry.name) & ".bas"
  92. VCS_IE_Functions.ExportObject acQuery, qry.name, full_path, VCS_File.UsingUcs2
  93. obj_count = obj_count + 1
  94. End If
  95. next_qry:
  96. Call SysCmd(4, "Export query: " & obj_count & " on " & db.QueryDefs.count)
  97. Next
  98. logger "ExportAllSource", "INFO", "> " & obj_count & " queries exported"
  99. For Each obj_type In Split( _
  100. "forms|Forms|" & acForm & "," & _
  101. "reports|Reports|" & acReport & "," & _
  102. "macros|Scripts|" & acMacro & "," & _
  103. "modules|Modules|" & acModule _
  104. , "," _
  105. )
  106. obj_type_split = Split(obj_type, "|")
  107. obj_type_label = obj_type_split(0)
  108. obj_type_name = obj_type_split(1)
  109. obj_type_num = val(obj_type_split(2))
  110. obj_path = source_path & obj_type_label & "\"
  111. obj_count = 0
  112. 'a retirer
  113. VCS_Dir.ClearTextFilesFromDir obj_path, "bas"
  114. logger "ExportAllSource", "INFO", "Exporting " & obj_type_label & "..."
  115. For Each doc In db.Containers(obj_type_name).Documents
  116. '### 11/10/2016: add optimizer
  117. If optimizer_activated() Then
  118. If Not needs_export(obj_type_num, doc.name) > 0 Then
  119. obj_count = obj_count + 1
  120. Call SysCmd(4, "Exporting " & obj_type_label & ": " & obj_count & " on " & db.Containers(obj_type_name).Documents.count)
  121. logger "ExportAllSource", "DEBUG", obj_type_label & " '" & doc.name & " skipped"
  122. GoTo next_doc
  123. End If
  124. End If
  125. '###
  126. DoEvents
  127. If (Left$(doc.name, 1) <> "~") And _
  128. (IsNotVCS(doc.name) Or ArchiveMyself) Then
  129. If obj_type_label = "modules" Then
  130. ucs2 = False
  131. Else
  132. ucs2 = VCS_File.UsingUcs2
  133. End If
  134. full_path = obj_path & VCS_IE_Functions.to_filename(doc.name) & ".bas"
  135. VCS_IE_Functions.ExportObject obj_type_num, doc.name, full_path, ucs2
  136. If obj_type_label = "reports" Then
  137. full_path = obj_path & VCS_IE_Functions.to_filename(doc.name) & ".pv"
  138. VCS_Report.ExportPrintVars doc.name, obj_path & doc.name & ".pv"
  139. End If
  140. Call SysCmd(4, "Exporting " & obj_type_label & ": " & obj_count & " on " & db.Containers(obj_type_name).Documents.count)
  141. obj_count = obj_count + 1
  142. End If
  143. next_doc:
  144. Next
  145. logger "ExportAllSource", "INFO", "> " & obj_count & " " & obj_type_label & " exported"
  146. Next
  147. Call SysCmd(4, "Exporting references")
  148. VCS_Reference.ExportReferences source_path
  149. '-------------------------table export------------------------
  150. Call SysCmd(4, "Exporting tables")
  151. obj_path = source_path & "tables\"
  152. VCS_Dir.MkDirIfNotExist Left$(obj_path, InStrRev(obj_path, "\"))
  153. VCS_Dir.ClearTextFilesFromDir obj_path, "txt", True
  154. Dim td As DAO.TableDef
  155. Dim tds As DAO.TableDefs
  156. Set tds = db.TableDefs
  157. obj_type_label = "tbldef"
  158. obj_type_name = "Table_Def"
  159. obj_type_num = acTable
  160. obj_path = source_path & obj_type_label & "\"
  161. obj_count = 0
  162. obj_data_count = 0
  163. VCS_Dir.MkDirIfNotExist Left$(obj_path, InStrRev(obj_path, "\"))
  164. 'move these into Table and DataMacro modules?
  165. ' - We don't want to determin file extentions here - or obj_path either!
  166. VCS_Dir.ClearTextFilesFromDir obj_path, "sql"
  167. VCS_Dir.ClearTextFilesFromDir obj_path, "xml"
  168. VCS_Dir.ClearTextFilesFromDir obj_path, "LNKD"
  169. Dim IncludeTablesCol As Collection
  170. Set IncludeTablesCol = StrSetToCol(include_tables, ",")
  171. logger "ExportAllSource", "INFO", "Exporting " & obj_type_label & "..."
  172. Dim update_this_tabledef As Boolean
  173. For Each td In tds
  174. '### 11/10/2016: add optimizer
  175. 'only update the table definition if this is a complete export
  176. 'or if the table definition has been modified since last export
  177. update_this_tabledef = (Not optimizer_activated() Or needs_export(acTable, td.name) > 0)
  178. '###
  179. ' This is not a system table
  180. ' this is not a temporary table
  181. If Left$(td.name, 4) <> "MSys" And _
  182. Left$(td.name, 1) <> "~" Then
  183. If Len(td.connect) = 0 Then ' this is not an external table
  184. If update_this_tabledef Then
  185. VCS_Table.ExportTableDef db, td, obj_path
  186. Else
  187. logger "ExportAllSource", "DEBUG", "TableDef " & td.name & " skipped"
  188. End If
  189. If include_tables = "*" Then
  190. DoEvents
  191. VCS_Table.ExportTableData CStr(td.name), source_path & "tables\"
  192. If Len(dir$(source_path & "tables\" & td.name & ".txt")) > 0 Then
  193. obj_data_count = obj_data_count + 1
  194. End If
  195. ElseIf (Len(Replace(include_tables, " ", vbNullString)) > 0) And include_tables <> "*" Then
  196. DoEvents
  197. On Error GoTo Err_TableNotFound
  198. If InCollection(IncludeTablesCol, td.name) Then
  199. VCS_Table.ExportTableData CStr(td.name), source_path & "tables\"
  200. obj_data_count = obj_data_count + 1
  201. End If
  202. Err_TableNotFound:
  203. 'else don't export table data
  204. End If
  205. Else
  206. If update_this_tabledef Then
  207. VCS_Table.ExportLinkedTable td.name, obj_path
  208. Else
  209. logger "ExportAllSource", "DEBUG", "TableDef " & td.name & " skipped"
  210. End If
  211. End If
  212. obj_count = obj_count + 1
  213. Call SysCmd(4, "Export table definition: " & obj_count & " on " & tds.count)
  214. End If
  215. next_td:
  216. Next
  217. logger "ExportAllSource", "INFO", "> " & obj_count & " tbldef exported"
  218. logger "ExportAllSource", "INFO", "> " & obj_data_count & " table's datas exported"
  219. logger "ExportAllSource", "INFO", "Export relations"
  220. obj_count = 0
  221. obj_path = source_path & "relations\"
  222. VCS_Dir.MkDirIfNotExist Left$(obj_path, InStrRev(obj_path, "\"))
  223. VCS_Dir.ClearTextFilesFromDir obj_path, "txt", True
  224. Dim aRelation As DAO.Relation
  225. Call SysCmd(4, "Exporting relations")
  226. For Each aRelation In CurrentDb.Relations
  227. ' Exclude relations from system tables and inherited (linked) relations
  228. If Not (aRelation.name = "MSysNavPaneGroupsMSysNavPaneGroupToObjects" _
  229. Or aRelation.name = "MSysNavPaneGroupCategoriesMSysNavPaneGroups" _
  230. Or (aRelation.Attributes And DAO.RelationAttributeEnum.dbRelationInherited) = _
  231. DAO.RelationAttributeEnum.dbRelationInherited) Then
  232. VCS_Relation.ExportRelation aRelation, obj_path & to_filename(aRelation.name) & ".txt"
  233. obj_count = obj_count + 1
  234. End If
  235. Next
  236. logger "ExportAllSource", "INFO", "> " & obj_count & " relations exported"
  237. logger "ExportAllSource", "INFO", "Export done"
  238. End Sub
  239. ' Main entry point for IMPORT. Import all forms, reports, queries,
  240. ' macros, modules, and lookup tables from `source` folder under the
  241. ' database's folder.
  242. Public Sub ImportAllSource()
  243. Dim FSO As Object
  244. Dim source_path As String
  245. Dim obj_path As String
  246. Dim obj_type As Variant
  247. Dim obj_type_split() As String
  248. Dim obj_type_label As String
  249. Dim obj_type_num As Integer
  250. Dim obj_count As Integer
  251. Dim filename As String
  252. Dim obj_name As String
  253. Dim ucs2 As Boolean
  254. logger "ImportAllSource", "INFO", "Begin 'Import all sources'"
  255. logger "ImportAllSource", "DEBUG", "Optimizer on: " & optimizer_activated()
  256. Set FSO = CreateObject("Scripting.FileSystemObject")
  257. CloseFormsReports
  258. 'InitUsingUcs2
  259. source_path = VCS_Dir.ProjectPath() & "source\"
  260. If Not FSO.FolderExists(source_path) Then
  261. logger "ImportAllSource", "CRITICAL", "No source found at:" & source_path
  262. End If
  263. Call ImportProperties(CurrentDb, source_path & "database.properties")
  264. If Not VCS_Reference.ImportReferences(source_path) Then
  265. logger "ImportAllSource", "INFO", "Info: no references file in " & source_path
  266. End If
  267. obj_path = source_path & "queries\"
  268. filename = dir$(obj_path & "*.bas")
  269. Dim tempFilePath As String
  270. tempFilePath = VCS_File.TempFile()
  271. If Len(filename) > 0 Then
  272. logger "ImportAllSource", "INFO", "Importing queries..."
  273. obj_count = 0
  274. Do Until Len(filename) = 0
  275. DoEvents
  276. obj_name = Mid$(filename, 1, InStrRev(filename, ".") - 1)
  277. obj_name = VCS_IE_Functions.to_accessname(obj_name)
  278. VCS_IE_Functions.ImportObject acQuery, obj_name, obj_path & filename, VCS_File.UsingUcs2
  279. VCS_IE_Functions.ExportObject acQuery, obj_name, tempFilePath, VCS_File.UsingUcs2
  280. VCS_IE_Functions.ImportObject acQuery, obj_name, tempFilePath, VCS_File.UsingUcs2
  281. obj_count = obj_count + 1
  282. filename = dir$()
  283. Loop
  284. logger "ImportAllSource", "INFO", "> " & obj_count & " queries imported"
  285. End If
  286. VCS_Dir.DelIfExist tempFilePath
  287. ' restore table definitions
  288. obj_path = source_path & "tbldef\"
  289. filename = dir$(obj_path & "*.sql")
  290. If Len(filename) > 0 Then
  291. logger "ImportAllSource", "INFO", "Importing TblDefs..."
  292. obj_count = 0
  293. Do Until Len(filename) = 0
  294. obj_name = Mid$(filename, 1, InStrRev(filename, ".") - 1)
  295. obj_name = VCS_IE_Functions.to_accessname(obj_name)
  296. VCS_Table.ImportTableDef CStr(obj_name), obj_path
  297. obj_count = obj_count + 1
  298. filename = dir$()
  299. Loop
  300. logger "ImportAllSource", "INFO", "> " & obj_count & " TblDefs imported"
  301. End If
  302. ' restore linked tables - we must have access to the remote store to import these!
  303. filename = dir$(obj_path & "*.LNKD")
  304. If Len(filename) > 0 Then
  305. logger "ImportAllSource", "INFO", "Importing Linked TblDefs..."
  306. obj_count = 0
  307. Do Until Len(filename) = 0
  308. obj_name = Mid$(filename, 1, InStrRev(filename, ".") - 1)
  309. obj_name = VCS_IE_Functions.to_accessname(obj_name)
  310. VCS_Table.ImportLinkedTable CStr(obj_name), obj_path
  311. obj_count = obj_count + 1
  312. filename = dir$()
  313. Loop
  314. logger "ImportAllSource", "INFO", "> " & obj_count & " Linked TblDefs imported"
  315. End If
  316. ' NOW we may load data
  317. obj_path = source_path & "tables\"
  318. filename = dir$(obj_path & "*.txt")
  319. If Len(filename) > 0 Then
  320. logger "ImportAllSource", "INFO", "Importing table's data..."
  321. obj_count = 0
  322. Do Until Len(filename) = 0
  323. DoEvents
  324. obj_name = Mid$(filename, 1, InStrRev(filename, ".") - 1)
  325. obj_name = VCS_IE_Functions.to_accessname(obj_name)
  326. VCS_Table.ImportTableData CStr(obj_name), obj_path
  327. obj_count = obj_count + 1
  328. filename = dir$()
  329. Loop
  330. logger "ImportAllSource", "INFO", "> " & obj_count & " table's data imported"
  331. End If
  332. 'load Data Macros - not DRY!
  333. obj_path = source_path & "tbldef\"
  334. filename = dir$(obj_path & "*.xml")
  335. If Len(filename) > 0 Then
  336. logger "ImportAllSource", "INFO", "Importing Data Macros..."
  337. obj_count = 0
  338. Do Until Len(filename) = 0
  339. DoEvents
  340. obj_name = Mid$(filename, 1, InStrRev(filename, ".") - 1)
  341. obj_name = VCS_IE_Functions.to_accessname(obj_name)
  342. 'VCS_Table.ImportTableData CStr(obj_name), obj_path
  343. VCS_DataMacro.ImportDataMacros obj_name, obj_path
  344. obj_count = obj_count + 1
  345. filename = dir$()
  346. Loop
  347. logger "ImportAllSource", "INFO", "> " & obj_count & " DataMacros imported"
  348. End If
  349. For Each obj_type In Split( _
  350. "forms|" & acForm & "," & _
  351. "reports|" & acReport & "," & _
  352. "macros|" & acMacro & "," & _
  353. "modules|" & acModule _
  354. , "," _
  355. )
  356. obj_type_split = Split(obj_type, "|")
  357. obj_type_label = obj_type_split(0)
  358. obj_type_num = val(obj_type_split(1))
  359. obj_path = source_path & obj_type_label & "\"
  360. filename = dir$(obj_path & "*.bas")
  361. If Len(filename) > 0 Then
  362. logger "ImportAllSource", "INFO", "Importing " & obj_type_label & "..."
  363. obj_count = 0
  364. Do Until Len(filename) = 0
  365. ' DoEvents no good idea!
  366. obj_name = Mid$(filename, 1, InStrRev(filename, ".") - 1)
  367. obj_name = VCS_IE_Functions.to_accessname(obj_name)
  368. If obj_type_label = "modules" Then
  369. ucs2 = False
  370. Else
  371. ucs2 = VCS_File.UsingUcs2
  372. End If
  373. If IsNotVCS(obj_name) Then
  374. VCS_IE_Functions.ImportObject obj_type_num, obj_name, obj_path & filename, ucs2
  375. obj_count = obj_count + 1
  376. Else
  377. If ArchiveMyself Then
  378. logger "ImportAllSource", "WARNING", "Module " & obj_name & " could not be updated while running. Ensure latest version is included!"
  379. End If
  380. End If
  381. filename = dir$()
  382. Loop
  383. logger "ImportAllSource", "INFO", "> " & obj_count & " " & obj_type_label & " imported"
  384. End If
  385. Next
  386. 'import Print Variables
  387. logger "ImportAllSource", "INFO", "Importing Print Vars..."
  388. obj_count = 0
  389. obj_path = source_path & "reports\"
  390. filename = dir$(obj_path & "*.pv")
  391. Do Until Len(filename) = 0
  392. DoEvents
  393. obj_name = Mid$(filename, 1, InStrRev(filename, ".") - 1)
  394. obj_name = VCS_IE_Functions.to_accessname(obj_name)
  395. VCS_Report.ImportPrintVars obj_name, obj_path & filename
  396. obj_count = obj_count + 1
  397. filename = dir$()
  398. Loop
  399. logger "ImportAllSource", "INFO", "> " & obj_count & " Print Vars imported"
  400. 'import relations
  401. logger "ImportAllSource", "INFO", "Importing Relations..."
  402. obj_count = 0
  403. obj_path = source_path & "relations\"
  404. filename = dir$(obj_path & "*.txt")
  405. Do Until Len(filename) = 0
  406. DoEvents
  407. VCS_Relation.ImportRelation obj_path & filename
  408. obj_count = obj_count + 1
  409. filename = dir$()
  410. Loop
  411. logger "ImportAllSource", "INFO", "> " & obj_count & " Relations imported"
  412. DoEvents
  413. logger "ImportAllSource", "INFO", "Import Done"
  414. End Sub
  415. ' Main entry point for ImportProject.
  416. ' Drop all forms, reports, queries, macros, modules.
  417. ' execute ImportAllSource.
  418. Public Sub ImportProject()
  419. On Error GoTo errorHandler
  420. If OA_MsgBox("This action will delete all existing: " & vbCrLf & _
  421. vbCrLf & _
  422. Chr$(149) & " Tables" & vbCrLf & _
  423. Chr$(149) & " Forms" & vbCrLf & _
  424. Chr$(149) & " Macros" & vbCrLf & _
  425. Chr$(149) & " Modules" & vbCrLf & _
  426. Chr$(149) & " Queries" & vbCrLf & _
  427. Chr$(149) & " Reports" & vbCrLf & _
  428. vbCrLf & _
  429. "Are you sure you want to proceed?", vbCritical + vbYesNo, _
  430. "Import Project") <> vbYes Then
  431. Exit Sub
  432. End If
  433. Dim db As DAO.Database
  434. Set db = CurrentDb
  435. CloseFormsReports
  436. Debug.Print
  437. Debug.Print "Deleting Existing Objects"
  438. Debug.Print
  439. Dim rel As DAO.Relation
  440. For Each rel In CurrentDb.Relations
  441. If Not (rel.name = "MSysNavPaneGroupsMSysNavPaneGroupToObjects" Or _
  442. rel.name = "MSysNavPaneGroupCategoriesMSysNavPaneGroups") Then
  443. CurrentDb.Relations.Delete (rel.name)
  444. End If
  445. Next
  446. Dim dbObject As Object
  447. For Each dbObject In db.QueryDefs
  448. DoEvents
  449. If Left$(dbObject.name, 1) <> "~" Then
  450. ' Debug.Print dbObject.Name
  451. db.QueryDefs.Delete dbObject.name
  452. End If
  453. Next
  454. Dim td As DAO.TableDef
  455. For Each td In CurrentDb.TableDefs
  456. If Left$(td.name, 4) <> "MSys" And _
  457. Left$(td.name, 1) <> "~" Then
  458. CurrentDb.TableDefs.Delete (td.name)
  459. End If
  460. Next
  461. Dim objType As Variant
  462. Dim objTypeArray() As String
  463. Dim doc As Object
  464. '
  465. ' Object Type Constants
  466. Const OTNAME As Byte = 0
  467. Const OTID As Byte = 1
  468. For Each objType In Split( _
  469. "Forms|" & acForm & "," & _
  470. "Reports|" & acReport & "," & _
  471. "Scripts|" & acMacro & "," & _
  472. "Modules|" & acModule _
  473. , "," _
  474. )
  475. objTypeArray = Split(objType, "|")
  476. DoEvents
  477. For Each doc In db.Containers(objTypeArray(OTNAME)).Documents
  478. DoEvents
  479. If (Left$(doc.name, 1) <> "~") And _
  480. (IsNotVCS(doc.name)) Then
  481. ' Debug.Print doc.Name
  482. DoCmd.DeleteObject objTypeArray(OTID), doc.name
  483. End If
  484. Next
  485. Next
  486. Debug.Print "================="
  487. Debug.Print "Importing Project"
  488. ImportAllSource
  489. Exit Sub
  490. errorHandler:
  491. Debug.Print "VCS_ImportExport.ImportProject: Error #" & err.Number & vbCrLf & _
  492. err.Description
  493. End Sub
  494. ' Expose for use as function, can be called by query
  495. Public Sub make()
  496. ImportProject
  497. End Sub
  498. '===================================================================================================================================
  499. '-----------------------------------------------------------'
  500. ' Helper Functions - these should be put in their own files '
  501. '-----------------------------------------------------------'
  502. ' Close all open forms.
  503. Private Sub CloseFormsReports()
  504. On Error GoTo errorHandler
  505. logger "CloseFormsReports", "DEBUG", "Close any opened form or report"
  506. Dim threshold As Integer
  507. threshold = 0
  508. Do While Forms.count > threshold
  509. If Forms(0).name = "OpenAccess" Then
  510. threshold = 1
  511. Else
  512. DoCmd.Close acForm, Forms(threshold).name
  513. End If
  514. 'DoEvents
  515. Loop
  516. Do While Reports.count > 0
  517. DoCmd.Close acReport, Reports(0).name
  518. 'DoEvents
  519. Loop
  520. DoEvents
  521. Exit Sub
  522. errorHandler:
  523. logger "CloseFormsReports", "CRITICAL", "Error #" & err.Number & err.Description
  524. End Sub
  525. 'errno 457 - duplicate key (& item)
  526. Public Function StrSetToCol(ByVal strSet As String, ByVal delimiter As String) As Collection 'throws errors
  527. Dim strSetArray() As String
  528. Dim col As Collection
  529. Set col = New Collection
  530. strSetArray = Split(strSet, delimiter)
  531. Dim item As Variant
  532. For Each item In strSetArray
  533. col.Add item, item
  534. Next
  535. Set StrSetToCol = col
  536. End Function
  537. ' Check if an item or key is in a collection
  538. Public Function InCollection(col As Collection, Optional vItem, Optional vKey) As Boolean
  539. On Error Resume Next
  540. Dim vColItem As Variant
  541. InCollection = False
  542. If Not IsMissing(vKey) Then
  543. col.item vKey
  544. '5 if not in collection, it is 91 if no collection exists
  545. If err.Number <> 5 And err.Number <> 91 Then
  546. InCollection = True
  547. End If
  548. ElseIf Not IsMissing(vItem) Then
  549. For Each vColItem In col
  550. If vColItem = vItem Then
  551. InCollection = True
  552. GoTo Exit_Proc
  553. End If
  554. Next vColItem
  555. End If
  556. Exit_Proc:
  557. Exit Function
  558. Err_Handle:
  559. Resume Exit_Proc
  560. End Function