views:

361

answers:

2

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.

+4  A: 
  • 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:

http://stackoverflow.com/questions/187506/how-do-you-use-version-control-with-access-development

http://stackoverflow.com/questions/247292/working-with-multiple-programmers-on-ms-access/250852#250852

Philippe Grondier
With queries, SaveAsText doesn't give you anything particularly useful. It's really only helpful with VBA objects.
David-W-Fenton
A: 

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
Michael Dillon