VCS_ImportExport.bas 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697
  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. 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, 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. logger "ExportAllSource", "INFO", "Export done"
  246. End Sub
  247. ' Main entry point for IMPORT. Import all forms, reports, queries,
  248. ' macros, modules, and lookup tables from `source` folder under the
  249. ' database's folder.
  250. Public Sub ImportAllSource()
  251. Dim FSO As Object
  252. Dim source_path As String
  253. Dim obj_path As String
  254. Dim obj_type As Variant
  255. Dim obj_type_split() As String
  256. Dim obj_type_label As String
  257. Dim obj_type_num As Integer
  258. Dim obj_count As Integer
  259. Dim filename As String
  260. Dim obj_name As String
  261. Dim ucs2 As Boolean
  262. logger "ImportAllSource", "INFO", "Begin 'Import all sources'"
  263. logger "ImportAllSource", "DEBUG", "Optimizer on: " & optimizer_activated()
  264. Set FSO = CreateObject("Scripting.FileSystemObject")
  265. CloseFormsReports
  266. 'InitUsingUcs2
  267. source_path = VCS_Dir.ProjectPath() & "source\"
  268. If Not FSO.FolderExists(source_path) Then
  269. logger "ImportAllSource", "CRITICAL", "No source found at:" & source_path
  270. End If
  271. Call ImportProperties(CurrentDb, source_path & "database.properties")
  272. If Not VCS_Reference.ImportReferences(source_path) Then
  273. logger "ImportAllSource", "INFO", "Info: no references file in " & source_path
  274. End If
  275. obj_path = source_path & "queries\"
  276. filename = dir$(obj_path & "*.bas")
  277. Dim tempFilePath As String
  278. tempFilePath = VCS_File.TempFile()
  279. If Len(filename) > 0 Then
  280. logger "ImportAllSource", "INFO", "Importing queries..."
  281. obj_count = 0
  282. Do Until Len(filename) = 0
  283. DoEvents
  284. obj_name = Mid$(filename, 1, InStrRev(filename, ".") - 1)
  285. obj_name = VCS_IE_Functions.to_accessname(obj_name)
  286. VCS_IE_Functions.ImportObject acQuery, obj_name, obj_path & filename, VCS_File.UsingUcs2
  287. VCS_IE_Functions.ExportObject acQuery, obj_name, tempFilePath, VCS_File.UsingUcs2
  288. VCS_IE_Functions.ImportObject acQuery, obj_name, tempFilePath, VCS_File.UsingUcs2
  289. obj_count = obj_count + 1
  290. filename = dir$()
  291. Loop
  292. logger "ImportAllSource", "INFO", "> " & obj_count & " queries imported"
  293. End If
  294. VCS_Dir.DelIfExist tempFilePath
  295. ' restore table definitions
  296. obj_path = source_path & "tbldef\"
  297. filename = dir$(obj_path & "*.sql")
  298. If Len(filename) > 0 Then
  299. logger "ImportAllSource", "INFO", "Importing TblDefs..."
  300. obj_count = 0
  301. Do Until Len(filename) = 0
  302. obj_name = Mid$(filename, 1, InStrRev(filename, ".") - 1)
  303. obj_name = VCS_IE_Functions.to_accessname(obj_name)
  304. VCS_Table.ImportTableDef CStr(obj_name), obj_path
  305. obj_count = obj_count + 1
  306. filename = dir$()
  307. Loop
  308. logger "ImportAllSource", "INFO", "> " & obj_count & " TblDefs imported"
  309. End If
  310. ' restore linked tables - we must have access to the remote store to import these!
  311. filename = dir$(obj_path & "*.LNKD")
  312. If Len(filename) > 0 Then
  313. logger "ImportAllSource", "INFO", "Importing Linked TblDefs..."
  314. obj_count = 0
  315. Do Until Len(filename) = 0
  316. obj_name = Mid$(filename, 1, InStrRev(filename, ".") - 1)
  317. obj_name = VCS_IE_Functions.to_accessname(obj_name)
  318. VCS_Table.ImportLinkedTable CStr(obj_name), obj_path
  319. obj_count = obj_count + 1
  320. filename = dir$()
  321. Loop
  322. logger "ImportAllSource", "INFO", "> " & obj_count & " Linked TblDefs imported"
  323. End If
  324. ' NOW we may load data
  325. obj_path = source_path & "tables\"
  326. filename = dir$(obj_path & "*.txt")
  327. If Len(filename) > 0 Then
  328. logger "ImportAllSource", "INFO", "Importing table's data..."
  329. obj_count = 0
  330. Do Until Len(filename) = 0
  331. DoEvents
  332. obj_name = Mid$(filename, 1, InStrRev(filename, ".") - 1)
  333. obj_name = VCS_IE_Functions.to_accessname(obj_name)
  334. VCS_Table.ImportTableData CStr(obj_name), obj_path
  335. obj_count = obj_count + 1
  336. filename = dir$()
  337. Loop
  338. logger "ImportAllSource", "INFO", "> " & obj_count & " table's data imported"
  339. End If
  340. 'load Data Macros - not DRY!
  341. obj_path = source_path & "tbldef\"
  342. filename = dir$(obj_path & "*.xml")
  343. If Len(filename) > 0 Then
  344. logger "ImportAllSource", "INFO", "Importing Data Macros..."
  345. obj_count = 0
  346. Do Until Len(filename) = 0
  347. DoEvents
  348. obj_name = Mid$(filename, 1, InStrRev(filename, ".") - 1)
  349. obj_name = VCS_IE_Functions.to_accessname(obj_name)
  350. 'VCS_Table.ImportTableData CStr(obj_name), obj_path
  351. VCS_DataMacro.ImportDataMacros obj_name, obj_path
  352. obj_count = obj_count + 1
  353. filename = dir$()
  354. Loop
  355. logger "ImportAllSource", "INFO", "> " & obj_count & " DataMacros imported"
  356. End If
  357. For Each obj_type In Split( _
  358. "forms|" & acForm & "," & _
  359. "reports|" & acReport & "," & _
  360. "macros|" & acMacro & "," & _
  361. "modules|" & acModule _
  362. , "," _
  363. )
  364. obj_type_split = Split(obj_type, "|")
  365. obj_type_label = obj_type_split(0)
  366. obj_type_num = val(obj_type_split(1))
  367. obj_path = source_path & obj_type_label & "\"
  368. filename = dir$(obj_path & "*.bas")
  369. If Len(filename) > 0 Then
  370. logger "ImportAllSource", "INFO", "Importing " & obj_type_label & "..."
  371. obj_count = 0
  372. Do Until Len(filename) = 0
  373. ' DoEvents no good idea!
  374. obj_name = Mid$(filename, 1, InStrRev(filename, ".") - 1)
  375. obj_name = VCS_IE_Functions.to_accessname(obj_name)
  376. If obj_type_label = "modules" Then
  377. ucs2 = False
  378. Else
  379. ucs2 = VCS_File.UsingUcs2
  380. End If
  381. If IsNotVCS(obj_name) Then
  382. VCS_IE_Functions.ImportObject obj_type_num, obj_name, obj_path & filename, ucs2
  383. obj_count = obj_count + 1
  384. Else
  385. If ArchiveMyself Then
  386. logger "ImportAllSource", "WARNING", "Module " & obj_name & " could not be updated while running. Ensure latest version is included!"
  387. End If
  388. End If
  389. filename = dir$()
  390. Loop
  391. logger "ImportAllSource", "INFO", "> " & obj_count & " " & obj_type_label & " imported"
  392. End If
  393. Next
  394. 'import Print Variables
  395. logger "ImportAllSource", "INFO", "Importing Print Vars..."
  396. obj_count = 0
  397. obj_path = source_path & "reports\"
  398. filename = dir$(obj_path & "*.pv")
  399. Do Until Len(filename) = 0
  400. DoEvents
  401. obj_name = Mid$(filename, 1, InStrRev(filename, ".") - 1)
  402. obj_name = VCS_IE_Functions.to_accessname(obj_name)
  403. VCS_Report.ImportPrintVars obj_name, obj_path & filename
  404. obj_count = obj_count + 1
  405. filename = dir$()
  406. Loop
  407. logger "ImportAllSource", "INFO", "> " & obj_count & " Print Vars imported"
  408. 'import relations
  409. logger "ImportAllSource", "INFO", "Importing Relations..."
  410. obj_count = 0
  411. obj_path = source_path & "relations\"
  412. filename = dir$(obj_path & "*.txt")
  413. Do Until Len(filename) = 0
  414. DoEvents
  415. VCS_Relation.ImportRelation obj_path & filename
  416. obj_count = obj_count + 1
  417. filename = dir$()
  418. Loop
  419. logger "ImportAllSource", "INFO", "> " & obj_count & " Relations imported"
  420. DoEvents
  421. logger "ImportAllSource", "INFO", "Import Done"
  422. End Sub
  423. ' Main entry point for ImportProject.
  424. ' Drop all forms, reports, queries, macros, modules.
  425. ' execute ImportAllSource.
  426. Public Sub ImportProject()
  427. On Error GoTo errorHandler
  428. If OA_MsgBox("This action will delete all existing: " & vbCrLf & _
  429. vbCrLf & _
  430. Chr$(149) & " Tables" & vbCrLf & _
  431. Chr$(149) & " Forms" & vbCrLf & _
  432. Chr$(149) & " Macros" & vbCrLf & _
  433. Chr$(149) & " Modules" & vbCrLf & _
  434. Chr$(149) & " Queries" & vbCrLf & _
  435. Chr$(149) & " Reports" & vbCrLf & _
  436. vbCrLf & _
  437. "Are you sure you want to proceed?", vbCritical + vbYesNo, _
  438. "Import Project") <> vbYes Then
  439. Exit Sub
  440. End If
  441. Dim db As DAO.Database
  442. Set db = CurrentDb
  443. CloseFormsReports
  444. Debug.Print
  445. Debug.Print "Deleting Existing Objects"
  446. Debug.Print
  447. Dim rel As DAO.Relation
  448. For Each rel In CurrentDb.Relations
  449. If Not (rel.name = "MSysNavPaneGroupsMSysNavPaneGroupToObjects" Or _
  450. rel.name = "MSysNavPaneGroupCategoriesMSysNavPaneGroups") Then
  451. CurrentDb.Relations.Delete (rel.name)
  452. End If
  453. Next
  454. Dim dbObject As Object
  455. For Each dbObject In db.QueryDefs
  456. DoEvents
  457. If Left$(dbObject.name, 1) <> "~" Then
  458. ' Debug.Print dbObject.Name
  459. db.QueryDefs.Delete dbObject.name
  460. End If
  461. Next
  462. Dim td As DAO.TableDef
  463. For Each td In CurrentDb.TableDefs
  464. If Left$(td.name, 4) <> "MSys" And _
  465. Left$(td.name, 1) <> "~" Then
  466. CurrentDb.TableDefs.Delete (td.name)
  467. End If
  468. Next
  469. Dim objType As Variant
  470. Dim objTypeArray() As String
  471. Dim doc As Object
  472. '
  473. ' Object Type Constants
  474. Const OTNAME As Byte = 0
  475. Const OTID As Byte = 1
  476. For Each objType In Split( _
  477. "Forms|" & acForm & "," & _
  478. "Reports|" & acReport & "," & _
  479. "Scripts|" & acMacro & "," & _
  480. "Modules|" & acModule _
  481. , "," _
  482. )
  483. objTypeArray = Split(objType, "|")
  484. DoEvents
  485. For Each doc In db.Containers(objTypeArray(OTNAME)).Documents
  486. DoEvents
  487. If (Left$(doc.name, 1) <> "~") And _
  488. (IsNotVCS(doc.name)) Then
  489. ' Debug.Print doc.Name
  490. DoCmd.DeleteObject objTypeArray(OTID), doc.name
  491. End If
  492. Next
  493. Next
  494. Debug.Print "================="
  495. Debug.Print "Importing Project"
  496. ImportAllSource
  497. Exit Sub
  498. errorHandler:
  499. Debug.Print "VCS_ImportExport.ImportProject: Error #" & err.Number & vbCrLf & _
  500. err.Description
  501. End Sub
  502. ' Expose for use as function, can be called by query
  503. Public Sub make()
  504. ImportProject
  505. End Sub
  506. '===================================================================================================================================
  507. '-----------------------------------------------------------'
  508. ' Helper Functions - these should be put in their own files '
  509. '-----------------------------------------------------------'
  510. ' Close all open forms.
  511. Private Sub CloseFormsReports()
  512. On Error GoTo errorHandler
  513. logger "CloseFormsReports", "DEBUG", "Close any opened form or report"
  514. Dim threshold As Integer
  515. threshold = 0
  516. Do While Forms.count > threshold
  517. If Forms(0).name = "OpenAccess" Then
  518. threshold = 1
  519. Else
  520. DoCmd.Close acForm, Forms(threshold).name
  521. End If
  522. 'DoEvents
  523. Loop
  524. Do While Reports.count > 0
  525. DoCmd.Close acReport, Reports(0).name
  526. 'DoEvents
  527. Loop
  528. DoEvents
  529. Exit Sub
  530. errorHandler:
  531. logger "CloseFormsReports", "CRITICAL", "Error #" & err.Number & err.Description
  532. End Sub
  533. 'errno 457 - duplicate key (& item)
  534. Public Function StrSetToCol(ByVal strSet As String, ByVal delimiter As String) As Collection 'throws errors
  535. Dim strSetArray() As String
  536. Dim col As Collection
  537. Set col = New Collection
  538. strSetArray = Split(strSet, delimiter)
  539. Dim item As Variant
  540. For Each item In strSetArray
  541. col.Add item, item
  542. Next
  543. Set StrSetToCol = col
  544. End Function
  545. ' Check if an item or key is in a collection
  546. Public Function InCollection(col As Collection, Optional vItem, Optional vKey) As Boolean
  547. On Error Resume Next
  548. Dim vColItem As Variant
  549. InCollection = False
  550. If Not IsMissing(vKey) Then
  551. col.item vKey
  552. '5 if not in collection, it is 91 if no collection exists
  553. If err.Number <> 5 And err.Number <> 91 Then
  554. InCollection = True
  555. End If
  556. ElseIf Not IsMissing(vItem) Then
  557. For Each vColItem In col
  558. If vColItem = vItem Then
  559. InCollection = True
  560. GoTo Exit_Proc
  561. End If
  562. Next vColItem
  563. End If
  564. Exit_Proc:
  565. Exit Function
  566. Err_Handle:
  567. Resume Exit_Proc
  568. End Function