OA_Import.bas 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. Option Compare Database
  2. Option Explicit
  3. Public Sub ImportAll()
  4. Dim db As DAO.Database
  5. Dim FSO As Object
  6. logger "ImportAll", "INFO", "Begin 'Import all sources'"
  7. Set FSO = CreateObject("Scripting.FileSystemObject")
  8. Set db = CurrentDb
  9. If Not FSO.FolderExists(source_dir()) Then
  10. logger "ImportAll", "CRITICAL", "No source found at:" & source_dir
  11. End If
  12. ' close any opened form or report, except OpenAccess's form
  13. Call CloseFormsReports
  14. ' import database properties
  15. Call ImportProperties(CurrentDb, joinpaths(source_dir, "database.properties"))
  16. Call ImportAllQueries
  17. Call ImportAllTables
  18. Call ImportAllLinkedTables
  19. Call ImportAllDataMacros
  20. Call ImportAllDocs(acForm)
  21. Call ImportAllDocs(acReport)
  22. Call ImportAllPrintVars
  23. Call ImportAllDocs(acMacro)
  24. Call ImportReferences
  25. Call ImportAllDocs(acModule)
  26. Call ImportAllRelations
  27. SaveProject
  28. logger "ImportAll", "INFO", "Import done"
  29. End Sub
  30. Public Sub ImportAllQueries()
  31. Dim dirpath, obj_name As String
  32. Dim filename As Variant
  33. Dim count, total As Integer
  34. dirpath = joinpaths(source_dir(), "queries\")
  35. logger "ImportAllQueries", "INFO", "Import queries"
  36. logger "ImportAllQueries", "DEBUG", "> import from: " & dirpath
  37. count = 0
  38. total = 0
  39. Dim to_import As String
  40. to_import = list_files_in(dirpath, "*.bas")
  41. total = UBound(Split(to_import, "|")) + 1
  42. If Len(to_import) > 0 Then
  43. For Each filename In Split(to_import, "|")
  44. obj_name = Mid$(filename, 1, InStrRev(filename, ".") - 1)
  45. obj_name = to_accessname(obj_name)
  46. ImportDocument acQuery, obj_name, joinpaths(dirpath, filename)
  47. count = count + 1
  48. Call SysCmd(acSysCmdSetStatus, "Import query: " & count & " on " & total)
  49. filename = dir$()
  50. Next filename
  51. logger "ImportAllQueries", "INFO", "> " & count & " queries imported"
  52. Else
  53. logger "ImportAllQueries", "INFO", "> No query to import"
  54. End If
  55. Call SysCmd(acSysCmdClearStatus)
  56. End Sub
  57. Public Sub ImportAllTables()
  58. Dim dirpath, obj_name As String
  59. Dim filename As Variant
  60. Dim count, total As Integer
  61. dirpath = joinpaths(source_dir(), "tables\")
  62. logger "ImportAllTables", "INFO", "Import local tables"
  63. logger "ImportAllTables", "DEBUG", "> import from: " & dirpath
  64. count = 0
  65. total = 0
  66. Dim to_import As String
  67. to_import = list_files_in(dirpath, "*.xml")
  68. total = UBound(Split(to_import, "|")) + 1
  69. If Len(to_import) > 0 Then
  70. For Each filename In Split(to_import, "|")
  71. ImportTable joinpaths(dirpath, filename)
  72. count = count + 1
  73. Call SysCmd(acSysCmdSetStatus, "Import local table: " & count & " on " & total)
  74. Next filename
  75. logger "ImportAllTables", "INFO", "> " & count & " local tables imported"
  76. Else
  77. logger "ImportAllTables", "INFO", "> No local table to import"
  78. End If
  79. Call SysCmd(acSysCmdClearStatus)
  80. End Sub
  81. Public Sub ImportAllLinkedTables()
  82. Dim dirpath, obj_name As String
  83. Dim filename As Variant
  84. Dim count, total As Integer
  85. dirpath = joinpaths(source_dir(), "tables\")
  86. logger "ImportAllLinkedTables", "INFO", "Import linked tables"
  87. logger "ImportAllLinkedTables", "DEBUG", "> import from: " & dirpath
  88. count = 0
  89. total = 0
  90. Dim to_import As String
  91. to_import = list_files_in(dirpath, "*.LNKD")
  92. total = UBound(Split(to_import, "|")) + 1
  93. If Len(to_import) > 0 Then
  94. For Each filename In Split(to_import, "|")
  95. obj_name = Mid$(filename, 1, InStrRev(filename, ".") - 1)
  96. obj_name = to_accessname(obj_name)
  97. ImportLinkedTable CStr(obj_name), dirpath
  98. count = count + 1
  99. Call SysCmd(acSysCmdSetStatus, "Import linked table: " & count & " on " & total)
  100. Next filename
  101. logger "ImportAllLinkedTables", "INFO", "> " & count & " Linked TblDefs imported"
  102. Else
  103. logger "ImportAllLinkedTables", "INFO", "> No linked table to import"
  104. End If
  105. Call SysCmd(acSysCmdClearStatus)
  106. End Sub
  107. Public Sub ImportAllDataMacros()
  108. Dim dirpath, obj_name As String
  109. Dim filename As Variant
  110. Dim count, total As Integer
  111. dirpath = joinpaths(source_dir(), "tbldef\")
  112. logger "ImportAllDataMacros", "INFO", "Import DataMacros"
  113. logger "ImportAllDataMacros", "DEBUG", "> import from: " & dirpath
  114. count = 0
  115. total = 0
  116. Dim to_import As String
  117. to_import = list_files_in(dirpath, "*.xml")
  118. total = UBound(Split(to_import, "|")) + 1
  119. If Len(to_import) > 0 Then
  120. For Each filename In Split(to_import, "|")
  121. obj_name = Mid$(filename, 1, InStrRev(filename, ".") - 1)
  122. obj_name = to_accessname(obj_name)
  123. ImportDataMacros obj_name, dirpath
  124. Call SysCmd(acSysCmdSetStatus, "Import DataMacro: " & count & " on " & total)
  125. count = count + 1
  126. Next filename
  127. logger "ImportAllDataMacros", "INFO", "> " & count & " DataMacros imported"
  128. Else
  129. logger "ImportAllDataMacros", "INFO", "> " & count & " DataMacros imported"
  130. End If
  131. Call SysCmd(acSysCmdClearStatus)
  132. End Sub
  133. Public Sub ImportAllDocs(ByVal acType As Integer, Optional ByVal encoding = "utf-8")
  134. Dim doc_label As String
  135. Dim dirpath, obj_name As String
  136. Dim filename As Variant
  137. Dim count, total As Integer
  138. 'get the document's container's name from it's type
  139. doc_label = get_container_name(acType)
  140. If Len(doc_label) = 0 Then
  141. logger "ImportAllDocs", "CRITICAL", "acType " & acType & " is not recognized!"
  142. Exit Sub
  143. End If
  144. dirpath = joinpaths(source_dir(), doc_label & "\")
  145. logger "ImportAllDocs", "INFO", "# Import " & doc_label
  146. logger "ImportAllDocs", "DEBUG", "> import from: " & dirpath
  147. count = 0
  148. total = 0
  149. Dim to_import As String
  150. to_import = list_files_in(dirpath, "*.bas")
  151. total = UBound(Split(to_import, "|")) + 1
  152. If Len(to_import) > 0 Then
  153. For Each filename In Split(to_import, "|")
  154. obj_name = Mid$(filename, 1, InStrRev(filename, ".") - 1)
  155. obj_name = to_accessname(obj_name)
  156. If IsNotVCS(obj_name) Then
  157. ImportDocument acType, obj_name, joinpaths(dirpath, filename)
  158. Else
  159. logger "ImportAllDocs", "WARNING", "Module " & obj_name & " could not be updated while running. Ensure latest version is included!"
  160. End If
  161. count = count + 1
  162. Call SysCmd(acSysCmdSetStatus, "Import " & doc_label & ": " & count & " on " & total)
  163. Next filename
  164. logger "ImportAllDocs", "INFO", "> " & count & " " & doc_label & " imported"
  165. Else
  166. logger "ImportAllDocs", "INFO", "> No " & doc_label & " to import"
  167. End If
  168. Call SysCmd(acSysCmdClearStatus)
  169. End Sub
  170. Public Sub ImportAllPrintVars()
  171. Dim dirpath, obj_name As String
  172. Dim filename As Variant
  173. Dim count, total As Integer
  174. dirpath = joinpaths(source_dir(), "reports\")
  175. logger "ImportAllPrintVars", "INFO", "Import Print Vars"
  176. logger "ImportAllPrintVars", "DEBUG", "> import from: " & dirpath
  177. count = 0
  178. total = 0
  179. Dim to_import As String
  180. to_import = list_files_in(dirpath, "*.pv")
  181. total = UBound(Split(to_import, "|")) + 1
  182. If Len(to_import) > 0 Then
  183. For Each filename In Split(to_import, "|")
  184. obj_name = Mid$(filename, 1, InStrRev(filename, ".") - 1)
  185. obj_name = to_accessname(obj_name)
  186. ImportPrintVars obj_name, joinpaths(dirpath, filename)
  187. count = count + 1
  188. Call SysCmd(acSysCmdSetStatus, "Import Print Vars: " & count & " on " & total)
  189. Next filename
  190. logger "ImportAllPrintVars", "INFO", "> " & count & " Print Vars imported"
  191. Else
  192. logger "ImportAllPrintVars", "INFO", "> No Print Vars to import"
  193. End If
  194. Call SysCmd(acSysCmdClearStatus)
  195. End Sub
  196. Public Sub ImportAllRelations()
  197. Dim dirpath As String
  198. Dim filename As Variant
  199. Dim count, total As Integer
  200. dirpath = joinpaths(source_dir(), "relations\")
  201. logger "ImportAllRelations", "INFO", "Import Relations"
  202. logger "ImportAllRelations", "DEBUG", "> import from: " & dirpath
  203. count = 0
  204. total = 0
  205. Dim to_import As String
  206. to_import = list_files_in(dirpath, "*.txt")
  207. total = UBound(Split(to_import, "|")) + 1
  208. If Len(to_import) > 0 Then
  209. For Each filename In Split(to_import, "|")
  210. ImportRelation joinpaths(dirpath, filename)
  211. count = count + 1
  212. Call SysCmd(acSysCmdSetStatus, "Import relation: " & count & " on " & total)
  213. Next filename
  214. logger "ImportAllRelations", "INFO", "> " & count & " Relations imported"
  215. Else
  216. logger "ImportAllRelations", "INFO", "> No relation to import"
  217. End If
  218. Call SysCmd(acSysCmdClearStatus)
  219. End Sub