Extracting Source Code from an MS Access DB

巧了我就是萌 提交于 2019-12-03 08:55:08

There is a better way. You can use Visual Sourcesafe (and possibly other SCCs) to version control code and objects in place: see this MSDN article

This may help:

    Sub AllCodeToDesktop()
       'The reference for the FileSystemObject Object is Windows Script Host Object Model
       'but it not necessary to add the reference for this procedure.

       Dim fs As Object
       Dim f As Object
       Dim strMod As String
       Dim mdl As Object
       Dim i As Integer

       Set fs = CreateObject("Scripting.FileSystemObject")

       'Set up the file.
       Set f = fs.CreateTextFile(SpFolder("Desktop") & "\" _
         & Replace(CurrentProject.Name, ".", "") & ".txt")

       'For each component in the project ...
       For Each mdl In VBE.ActiveVBProject.VBComponents
           'using the count of lines ...
           i = VBE.ActiveVBProject.VBComponents(mdl.Name).CodeModule.CountOfLines
           'put the code in a string ...
           If VBE.ActiveVBProject.VBComponents(mdl.Name).codemodule.CountOfLines > 0 Then
              strMod = VBE.ActiveVBProject.VBComponents(mdl.Name).codemodule.Lines(1, i)
           End If
           'and then write it to a file, first marking the start with
           'some equal signs and the component name.
           f.writeline String(15, "=") & vbCrLf & mdl.Name _
               & vbCrLf & String(15, "=") & vbCrLf & strMod
       Next

       'Close eveything
       f.Close
       Set fs = Nothing
   End Sub

   Function SpFolder(SpName As String)
   'Special folders
       SpFolder = CreateObject("WScript.Shell").SpecialFolders(SpName)
   End Function  

From: http://wiki.lessthandot.com/index.php/Code_and_Code_Windows

You could use the undocumented Application.SaveAsText and Application.LoadFromText functions. SaveAsText works on modules, forms, and reports; and when you save a form or report as text, its module code will appear at the bottom of the resulting text file.

You could write a routine that would save all of the non-data objects in your Access MDB (or ADP) as text, put it in a module, and just keep that module in a development version of your Access DB. Then you could run the routine and check in the dumped code in VSS.

It's probably not as elegant as the Visual SourceSafe method described by Mitch Wheat, but that depends on what you want to do with the source code. I tend to hang onto multiple versions of MDB's, and use this method to compare source code between them using diff tools such as WinMerge. It's good for porting functionality between branches of development.

It's also good for locating all references to fields or controls wherever they may be found. Viewing Access objects as textual definitions makes finding these references dead simple.

Yarik

You might also want to take a look at his Q&A:

Working with multiple programmers on MS Access

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