tags:

views:

167

answers:

2

I've been trying to find some information about getting access to the raw code in MS Access (I use v2007 but should probably apply to all versions).

Say for instance that I'd like to list all functions in every code-behind form and module in the application and list their parameters.

How would you achieve this?

Note: I'm of course assuming that the application is not compiled.

+4  A: 

You can output all the code to text and run it though another program or load it into a database, or you can write code to access the code using VBE.

   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

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

Remou
Thanks, I knew I was missing something, couldn't remember that there was a VBE object. Thanks again :-)
Renaud Bompuis
+1  A: 

Is it possible to call the VBE object from another program? Sorry to raise this from the dead, I have the new discussion here

Fidel