VCS_ImportExport.bas 22 KB

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