tags:

views:

125

answers:

4

Is there any way to bulk-export Microsoft Access code to files? I see I can export one file at a time, but there are hundreds and I'll be here all day. It there no "Export All" or multi-select export anywhere?

+1  A: 

There is nothing in the interface to export more than one module at a time.

You can code your own "export all" equivalent easily:

Public Sub ExportModules()
Const cstrExtension As String = ".bas"
Dim objModule As Object
Dim strFolder As String
Dim strDestination As String

strFolder = CurrentProject.Path

For Each objModule In CurrentProject.AllModules
    strDestination = strFolder & Chr(92) & objModule.Name & cstrExtension
    Application.SaveAsText acModule, objModule.Name, strDestination
Next objModule
End Sub
HansUp
how do I run that? I'm not an access guy... sorry
arcticpenguin
that only works for the module code - how do I get the forms and reports?
arcticpenguin
@articpenguin I didn't know if that would be adequate for your needs, but thought I'd take a shot. You can use the undocument SaveAsText method for other database objects such as forms and reports. You can find more detailed information at the link Patrick gave you. I used the method I offered by calling it from the click event of a command button on a form.
HansUp
@articpenguin I have added a note on using VBE in a separate post. @HansUp SaveAsText will get you everything, including controls.
Remou
@Remou I see what you mean. I forgot he only asked for the code. I'm glad we have you around. :-)
HansUp
+1  A: 

To output all code to desktop, including code from forms and reports, you can paste this into a standard module and run it by pressing F5 or step through with F8. You may wish to fill in the name of the desktop folder first.

   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.
   ''SpFolder is a small function, but it would be better to fill in a
   ''path name instead of SpFolder(Desktop), eg "c:\users\somename\desktop"
   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 i > 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

To get special folders, you can use the list supplied by Microsoft.

Enumerating Special Folders: http://www.microsoft.com/technet/scriptcenter/guide/sas_fil_higv.mspx?mfr=true

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

Remou
This answer worked best for me, even if there were a few syntax issues. I was able to get the text I need in order to grep.
arcticpenguin
+1  A: 

You can do this without having to write any code at all. From the menu, choose tools->analyze->database documenter.

This will give you a bunch of options to print out the code. You can then while viewing the report ether send it out to your PDF printer (if you have one). Or, simply print out to a text file printer. Or you can even then click on the word option in the report menu bar and the results will be sent out to word

The database documenter has provisions to print out all code, including code in forms.

So, in place of some of the suggested code examples you can do this without having to write any code at all. Do play with the additional options in the documenter. The documenter will produce HUGE volumes print out information for every single property and object in the database. So, if you don't un-check some of the options then you will easily empty a full size printer tray of paper. This documenter thus results in huge printouts.

Albert D. Kallal
this also works
arcticpenguin