OA_Export.bas 7.7 KB

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