Serialize MS Access Database Objects to Text File(s)

烈酒焚心 提交于 2019-12-22 18:48:16

问题


Is there some code out there that lets me serialize all the objects in an MS Access MDB File.

All the Objects like Table definitions, Table Data, Query defintions, Report definitions, VB Modules should be written to one or multiple text files.

It is not necessary to reverse the operation (but would be nice to have). I want to put the text files to a VCS so I can track changes and document.


回答1:


  • To import/export Access forms, modules or macros from/to text files, use the undocumented LoadFromText/SaveAsText methods of the application object. (it seems you can use the same methods with query and report objects)
  • For tables, you can use the transferDatabase method of the DoCmd object. Be careful. By doing so you will loose the table structures and comparing text files content will be very hazardous. I'd advise you to develop your own tool for table structure comparison. I guess some pieces of software are also available on the net (google for MS Access table comparison)
  • To compare different versions of the same forms/modules/macros as text files, use a softare such as Files Compare Tool

You will have to write some 'cleaning' code when exporting with the SaveAsText commande, in order to ease file comparison by (for example) suppressing line numbers or internal access references.

Please check also the following links:

How do you use version control with Access development?

Working with multiple programmers on MS Access




回答2:


Not sure what David Fenton's comment refers to since there is more than one way to do SaveAsText. If you do it as follows, it should be useful.

  For Each obj In Access.Application.CurrentData.AllQueries
    Access.Application.SaveAsText acQuery, obj.Name, strFilePath & "\Query_" & obj.Name & ".txt"
  Next

As far as table definitions go, you may wish to try out the XML Export feature as follows:

  For Each obj In Access.Application.CurrentData.AllTables
    Access.Application.ExportXML acExportTable, obj.Name, _
      strFilePath & "\TData_" & obj.Name & ".xml", _
      strFilePath & "\TDef_" & obj.Name & ".xsd", , , acUTF8
  Next


来源:https://stackoverflow.com/questions/1290582/serialize-ms-access-database-objects-to-text-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!