VCS_ImportExport.bas 23 KB

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