VCS_ImportExport.bas 23 KB

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