Export Modules to Text Files in Microsoft Access

by demtron on Sunday, October 12, 2008 09:12 PM

I was recently asked to review the code differences between two Access databases.  One was the then-current production version of the database.  The other was a version that was being modified with new business rules.  As a first pass, I decided to export all the form, report, and code modules from each database into separate text files in separate folders, then use a source code comparison tool to compare both sets of files for changes.

I may need to create some code that will compare other objects such as tables and queries, but for right now, comparing source code files has proved to be a good start for getting a handle on the changes.  Here's the code I used to export all the modules.

Option Compare Database
Option Explicit
Public Sub CreateModuleFiles()
'On Error GoTo Err_Handler
Dim accObj As AccessObject  'Each module/form/report.
Dim bWasOpen As Boolean     'Flag to leave form/report open if it was open.
Dim strDoc As String        'Name of each form/report
'Stand-alone modules.
For Each accObj In CurrentProject.AllModules
Call WriteOutModules(accObj.Name, True)
Next
'Modules behind forms.
For Each accObj In CurrentProject.AllForms
strDoc = accObj.Name
bWasOpen = accObj.IsLoaded
If Not bWasOpen Then
DoCmd.OpenForm strDoc, acDesign, WindowMode:=acHidden
End If
If Forms(strDoc).HasModule Then
Call WriteOutModules("Form_" & accObj.Name, False)
End If
If Not bWasOpen Then
DoCmd.Close acForm, strDoc, acSaveNo
End If
Next
'Modules behind reports.
For Each accObj In CurrentProject.AllReports
strDoc = accObj.Name
bWasOpen = accObj.IsLoaded
If Not bWasOpen Then
'In Access 2000, remove the ", WindowMode:=acHidden" from the next line.
DoCmd.OpenReport strDoc, acDesign, WindowMode:=acHidden
End If
If Reports(strDoc).HasModule Then
Call WriteOutModules("Report_" & accObj.Name, False)
End If
If Not bWasOpen Then
DoCmd.Close acReport, strDoc, acSaveNo
End If
Next
End Sub
Private Function WriteOutModules(strModule As String, bIsStandAlone As Boolean)
Dim strCode As String
Dim bWasOpen As Boolean     'Flag applies to standalone modules only.
Dim lngLineNo As Long
If bIsStandAlone Then
bWasOpen = CurrentProject.AllModules(strModule).IsLoaded
End If
If Not bWasOpen Then
DoCmd.OpenModule strModule
End If
For lngLineNo = 1 To Modules(strModule).CountOfLines
strCode = strCode & Modules(strModule).Lines(lngLineNo, 1) & vbCrLf
Next
strCode = strCode & vbCrLf & vbCrLf & vbCrLf
If Not bWasOpen Then
On Error Resume Next
DoCmd.Close acModule, strModule, acSaveNo
End If
Dim intFile As Integer
'*** Set to next free open number ***
intFile = FreeFile()
Open "C:\output\modules\" & strModule & ".txt"   
For Output As #intFile
Print #intFile, strCode
Close #intFile
Debug.Print strModule & " complete"
DoEvents
End Function

Listing Object Library Reference Information in MS Access

by demtron on Friday, October 10, 2008 03:17 PM

When writing documentation for a Microsoft Access application, it's often important to provide information for on the object library references, especially for those apps that depend heavily on 3rd party or custom components. It's easy to obtain a list of references used, but what about attributes like File Version, Description, and Company? We can get these by opening the file properties in Windows Explorer and viewing the Version tab. If there are more than just a few references, this can be time consuming, especially if various attributes need to be copied and pasted elsewhere.

TypeLib comes to the rescue! TypeLib is a system DLL that can read the metadata contained in a DLL. Simply set a reference to %windir%\tlbinf32.dll, then add and run the following code in a module:

Public Sub ListAllReferences()
    Dim ref As Reference
    Dim tl As TLI.TypeLibInfo
    For Each ref In Access.Reference
        Set tl = New TLI.TypeLibInfo
        tl.ContainingFile = ref.FullPath
        Debug.Print ref.Name & "," & tl.HelpString & "," & ref.BuiltIn & "," & ref.FullPath
    Next ref
End Sub

Enjoy!


Microsoft Access Module Code List Generator

by demtron on Sunday, September 28, 2008 07:35 PM

I recently needed to generate a single file containing all the VBA code for a client's Microsoft Access 2003 application.  I originally wrote similar code about 8 years ago for Access 2000 but was unable to find it for this project. Undecided  So, I just decided to write it again and post it for everyone to use.  The code generates a header and lie numbers for each module.  Enjoy! 

Option Compare Database
Option Explicit
Public strAllCode As String
Public Sub StringAllLines()
Dim accObj As AccessObject  'Each module/form/report.
Dim bWasOpen As Boolean     'Flag to leave form/report open if it was open.
Dim strDoc As String        'Name of each form/report
'Stand-alone modules.
For Each accObj In CurrentProject.AllModules
Call GetModuleLines(accObj.Name, True)
Next
'Modules behind forms.
For Each accObj In CurrentProject.AllForms
strDoc = accObj.Name
bWasOpen = accObj.IsLoaded
If Not bWasOpen Then
DoCmd.OpenForm strDoc, acDesign, WindowMode:=acHidden
End If
If Forms(strDoc).HasModule Then
Call GetModuleLines("Form_" & accObj.Name, False)
End If
If Not bWasOpen Then
DoCmd.Close acForm, strDoc, acSaveNo
End If
Next
'Modules behind reports.
For Each accObj In CurrentProject.AllReports
strDoc = accObj.Name
bWasOpen = accObj.IsLoaded
If Not bWasOpen Then
'In Access 2000, remove the ", WindowMode:=acHidden" from the next line.
DoCmd.OpenReport strDoc, acDesign, WindowMode:=acHidden
End If
If Reports(strDoc).HasModule Then
Call GetModuleLines("Report_" & accObj.Name, False)
End If
If Not bWasOpen Then
DoCmd.Close acReport, strDoc, acSaveNo
End If
Next
Dim intFile As Integer
'*** Set to next free open number ***
intFile = FreeFile()
Open "c:\AllCode.txt" For Output As #intFile
Print #intFile, strAllCode
Close #intFile
End Sub
Private Function GetModuleLines(strModule As String, bIsStandAlone As Boolean)
Dim bWasOpen As Boolean     'Flag applies to standalone modules only.
Dim lngLineNo As Long
If bIsStandAlone Then
bWasOpen = CurrentProject.AllModules(strModule).IsLoaded
End If
If Not bWasOpen Then
DoCmd.OpenModule strModule
End If
strAllCode = strAllCode & "**********" & vbCrLf
strAllCode = strAllCode & strModule & vbCrLf
strAllCode = strAllCode & "**********" & vbCrLf
For lngLineNo = 1 To Modules(strModule).CountOfLines
strAllCode = strAllCode & Right("     " & lngLineNo, 5) & ": " & Modules(strModule).Lines(lngLineNo, 1) & vbCrLf
Next
strAllCode = strAllCode & vbCrLf & vbCrLf & vbCrLf
If Not bWasOpen Then
On Error Resume Next
DoCmd.Close acModule, strModule, acSaveNo
End If
Debug.Print strModule & " complete"
DoEvents
End Function

Powered by BlogEngine.NET 1.5.1.18
Theme by Mads Kristensen · Adapted by Demtron

Bookmark and Share

Calendar

<<  December 2024  >>
MoTuWeThFrSaSu
2526272829301
2345678
9101112131415
16171819202122
23242526272829
303112345

View posts in large calendar
Log in

Milwaukee SEO Company

Milwaukee Access Programmer/Developer

Milwaukee Website Designer and Developer



Marketing / SEO

Blog Directory
blogarama - the blog directory
TopOfBlogs
Milwaukee area SEO, SEM, ASP.Net