VCS_ImportExport.bas 24 KB

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