OA_Export.bas 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. Option Compare Database
  2. Option Explicit
  3. Public Sub ExportAll(Optional ByVal newer_only As Boolean = False)
  4. Dim db As DAO.Database
  5. logger "ExportAllSource", "INFO", "Begin 'Export all sources'"
  6. logger "ExportAllSource", "DEBUG", "> Newer only: " & newer_only
  7. ' try to save current project
  8. Call SaveProject
  9. Set db = CurrentDb
  10. ' close any opened form or report, except OpenAccess's form
  11. Call CloseFormsReports
  12. ' export database properties
  13. Call ExportProperties(CurrentDb, joinpaths(source_dir, "database.properties"))
  14. Call ExportAllQueries(newer_only)
  15. Call ExportAllDocs(acForm, newer_only)
  16. Call ExportAllDocs(acReport, newer_only)
  17. Call ExportAllDocs(acMacro, newer_only)
  18. Call ExportAllDocs(acModule, newer_only)
  19. Call ExportAllTblDefs(newer_only)
  20. Call ExportAllTableDatas
  21. Call ExportReferences
  22. Call ExportAllRelations
  23. logger "ExportAll", "INFO", "Export done"
  24. End Sub
  25. Public Sub ExportAllQueries(Optional ByVal newer_only As Boolean = False)
  26. Dim dirpath As String
  27. Dim count, total As Integer
  28. Dim file_path As String
  29. Dim db As DAO.Database
  30. Set db = CurrentDb()
  31. Dim qry As Object
  32. dirpath = joinpaths(source_dir(), "queries\")
  33. mktree dirpath
  34. logger "ExportAllQueries", "INFO", "Export queries"
  35. logger "ExportAllQueries", "DEBUG", "> export to: " & dirpath
  36. logger "ExportAllQueries", "DEBUG", "> Newer only: " & newer_only
  37. count = 0
  38. If newer_only Then
  39. total = UBound(Split(list_to_export(acQuery), ";")) + 1
  40. Else
  41. total = db.QueryDefs.count
  42. End If
  43. For Each qry In db.QueryDefs
  44. If Left$(qry.name, 1) = "~" Then
  45. logger "ExportAllQueries", "DEBUG", "Query " & qry.name & " ignored"
  46. GoTo next_qry
  47. End If
  48. If newer_only Then
  49. If Not needs_export(acQuery, qry.name) > 0 Then
  50. logger "ExportAllQueries", "DEBUG", "Query " & qry.name & " skipped"
  51. GoTo next_qry
  52. End If
  53. End If
  54. 'DoEvents 'utility?
  55. file_path = joinpaths(dirpath, to_filename(qry.name) & ".bas")
  56. ExportDocument acQuery, qry.name, file_path
  57. count = count + 1
  58. Call SysCmd(acSysCmdSetStatus, "Export query: " & count & " on " & total)
  59. next_qry:
  60. Next
  61. Call SysCmd(acSysCmdClearStatus)
  62. logger "ExportAllQueries", "INFO", "> " & count & " queries exported"
  63. End Sub
  64. Public Sub ExportAllDocs(ByVal acType As Integer, Optional ByVal newer_only As Boolean = False)
  65. 'export all the documents of the acType
  66. Dim doc_label As String
  67. Dim dirpath As String
  68. Dim count, total As Integer
  69. Dim file_path As String
  70. Dim db As DAO.Database
  71. Set db = CurrentDb()
  72. Dim doc As Object
  73. 'get the document's container's name from it's type
  74. doc_label = get_container_name(acType)
  75. If Len(doc_label) = 0 Then
  76. logger "ExportAllDoc", "CRITICAL", "acType " & acType & " is not recognized!"
  77. Exit Sub
  78. End If
  79. dirpath = joinpaths(source_dir(), doc_label & "\")
  80. mktree dirpath
  81. logger "ExportAllDocs", "INFO", "# Export " & doc_label
  82. logger "ExportAllDocs", "DEBUG", "> export to: " & dirpath
  83. logger "ExportAllDocs", "DEBUG", "> newer only: " & newer_only
  84. count = 0
  85. If newer_only Then
  86. total = UBound(Split(list_to_export(acType), ";")) + 1
  87. Else
  88. total = db.Containers(doc_label).Documents.count
  89. End If
  90. For Each doc In db.Containers(doc_label).Documents
  91. If Left$(doc.name, 1) = "~" Then
  92. logger "ExportAllDocs", "DEBUG", doc_label & ": " & doc.name & " ignored"
  93. GoTo next_doc
  94. End If
  95. If newer_only Then
  96. If Not needs_export(acType, doc.name) > 0 Then
  97. logger "ExportAllDocs", "DEBUG", doc_label & ": '" & doc.name & " skipped"
  98. GoTo next_doc
  99. End If
  100. End If
  101. file_path = joinpaths(dirpath, to_filename(doc.name) & ".bas")
  102. ExportDocument acType, doc.name, file_path
  103. If doc_label = "reports" Then
  104. file_path = joinpaths(dirpath, to_filename(doc.name) & ".pv")
  105. ExportPrintVars doc.name, file_path
  106. End If
  107. Call SysCmd(acSysCmdSetStatus, "Exporting " & doc_label & ": " & count & " on " & total)
  108. count = count + 1
  109. next_doc:
  110. Next
  111. Call SysCmd(acSysCmdClearStatus)
  112. logger "ExportAllDocs", "INFO", "> " & count & " " & doc_label & " exported"
  113. End Sub
  114. Public Sub ExportAllTblDefs(Optional ByVal newer_only As Boolean = False)
  115. 'export table definitions
  116. Dim dirpath, file_path As String
  117. Dim count, total As Integer
  118. Dim td As DAO.TableDef
  119. Dim tds As DAO.TableDefs
  120. Dim db As DAO.Database
  121. Set db = CurrentDb()
  122. dirpath = joinpaths(source_dir(), "tbldefs\")
  123. mktree dirpath
  124. logger "ExportTblDefs", "INFO", "Export tabledefs"
  125. logger "ExportTblDefs", "DEBUG", "> export to: " & dirpath
  126. logger "ExportTblDefs", "DEBUG", "> Newer only: " & newer_only
  127. Set tds = db.TableDefs
  128. count = 0
  129. If newer_only Then
  130. total = UBound(Split(list_to_export(acTable), ";")) + 1
  131. Else
  132. total = tds.count
  133. End If
  134. For Each td In tds
  135. If Left$(td.name, 1) = "~" Or Left$(td.name, 4) = "MSys" Then
  136. logger "ExportAllTblDefs", "DEBUG", "tables: " & td.name & " ignored"
  137. GoTo next_td
  138. End If
  139. If newer_only Then
  140. If Not needs_export(acTable, td.name) > 0 Then
  141. logger "ExportAllTblDefs", "DEBUG", "tables: " & td.name & " skipped"
  142. GoTo next_td
  143. End If
  144. End If
  145. If Len(td.connect) = 0 Then ' this is not an external table
  146. ExportTableDef CurrentDb, td, dirpath
  147. Else
  148. ExportLinkedTable td.name, dirpath
  149. End If
  150. count = count + 1
  151. Call SysCmd(4, "Export table definition: " & count & " on " & total)
  152. next_td:
  153. Next
  154. Call SysCmd(acSysCmdClearStatus)
  155. logger "ExportAllTblDefs", "INFO", "> " & count & " tbldefs exported"
  156. End Sub
  157. Public Sub ExportAllTableDatas()
  158. Dim dirpath, include_tables As String
  159. Dim count, total As Integer
  160. Dim td As DAO.TableDef
  161. dirpath = joinpaths(source_dir(), "tables\")
  162. mktree dirpath
  163. logger "ExportTableDatas", "INFO", "Export table's data"
  164. logger "ExportTableDatas", "DEBUG", "> export to: " & dirpath
  165. count = 0
  166. include_tables = get_include_tables()
  167. count = 0
  168. total = UBound(Split(include_tables, ",")) + 1
  169. Dim IncludeTablesCol As Collection
  170. Set IncludeTablesCol = StrSetToCol(include_tables, ",")
  171. For Each td In CurrentDb.TableDefs()
  172. If InCollection(IncludeTablesCol, td.name) Or include_tables = "*" Then
  173. If Len(td.connect) <> 0 Then ' this is not an external table
  174. logger "ExportTableDatas", "ERROR", td.name & " >> You can't export data from a linked table"
  175. GoTo next_td
  176. End If
  177. ExportTableData CStr(td.name), dirpath
  178. count = count + 1
  179. Call SysCmd(4, "Export table's data: " & count & " on " & total)
  180. End If
  181. next_td:
  182. Next
  183. Call SysCmd(acSysCmdClearStatus)
  184. logger "ExportTableDatas", "INFO", "> " & count & " table's datas exported"
  185. End Sub
  186. Public Sub ExportAllRelations()
  187. Dim dirpath, filepath As String
  188. Dim count, total As Integer
  189. dirpath = joinpaths(source_dir(), "relations\")
  190. mktree dirpath
  191. logger "ExportRelations", "INFO", "Export relations"
  192. logger "ExportRelations", "DEBUG", "> export to: " & dirpath
  193. count = 0
  194. Dim aRelation As DAO.Relation
  195. total = CurrentDb.Relations.count
  196. For Each aRelation In CurrentDb.Relations
  197. ' Exclude relations from system tables and inherited (linked) relations
  198. If Not (aRelation.name = "MSysNavPaneGroupsMSysNavPaneGroupToObjects" _
  199. Or aRelation.name = "MSysNavPaneGroupCategoriesMSysNavPaneGroups" _
  200. Or (aRelation.Attributes And DAO.RelationAttributeEnum.dbRelationInherited) = _
  201. DAO.RelationAttributeEnum.dbRelationInherited) Then
  202. filepath = joinpaths(dirpath, to_filename(aRelation.name) & ".txt")
  203. ExportRelation aRelation, filepath
  204. count = count + 1
  205. Call SysCmd(4, "Export relation: " & count & " on " & total)
  206. End If
  207. Next
  208. Call SysCmd(acSysCmdClearStatus)
  209. logger "ExportAllSource", "INFO", "> " & count & " relations exported"
  210. End Sub