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