getting a list of forms & classes

P

Peter Ignarson

Hi, I want to put a button on a form in Microsoft Access 2002 and in the
click event for the button whave some code that works out all the forms in
my Access database. How can I get a list/collection of all the forms in the
Access application (or can this even be done) ? I've done a Google search
using obvious terms like "Access AND reflection" but these are not the
correct terms.

Any pointers appreciated
Thank you
Pete
 
A

Albert D. Kallal

here is a "rough" peice of code I use to count the number of lines in an
appctions. The output looks like:

lines of code in Modules = 8670
Lines of code in forms = 16409
Lines of code in reports = 2290

total lines of code = 27369
number of Forms = 162
number of Reports = 73
number of tables (total) = 61
number of tables (user) = 55
number of modules = 23
number of Queries = 181


Note that you can use the built in documenter to list out all things your
database (tools->analyze->Documenter).

Anyway, here is the rough code:

Function LinesOfCode()

Dim db As Database
Dim Doc As Document
Dim mdl As Module
Dim lngCount As Long
Dim lngFormsCode As Long
Dim lngReportsCode As Long
Dim i As Integer
Dim j As Integer
Dim strForm As String
Dim intOneModule As Integer

Set db = CurrentDb()
' count module LOC
For Each Doc In db.Containers("Modules").Documents
Debug.Print Doc.Name;

DoCmd.OpenModule Doc.Name
Set mdl = Modules(Doc.Name)
Debug.Print " ", mdl.CountOfLines

lngCount = lngCount + mdl.CountOfLines
Set mdl = Nothing
DoCmd.Close acModule, Doc.Name
Next

Debug.Print "lines of code in Modules = " & lngCount


' count Code in Forms
For i = 0 To db.Containers("Forms").Documents.Count - 1
strForm = db.Containers("Forms").Documents(i).Name

DoCmd.OpenForm strForm, acDesign
lngFormsCode = lngFormsCode + Forms(strForm).Module.CountOfLines
'Debug.Print strForm & " = " & Forms(strForm).Module.CountOfLines
DoCmd.Close acForm, strForm, acSaveNo

Next

Debug.Print "Lines of code in forms = " & lngFormsCode

' cound LOC in Reports
For i = 0 To db.Containers("Reports").Documents.Count - 1
strForm = db.Containers("Reports").Documents(i).Name
DoCmd.OpenReport strForm, acViewDesign
lngReportsCode = lngReportsCode + Reports(strForm).Module.CountOfLines
DoCmd.Close acReport, strForm, acSaveNo
Next

Debug.Print "Lines of code in reports = " & lngReportsCode

Debug.Print "total lines of code = " & lngFormsCode + lngCount +
lngReportsCode

' number of forms, reports
Debug.Print "number of Forms = " &
db.Containers("Forms").Documents.Count
Debug.Print "number of Reports = " &
db.Containers("Reports").Documents.Count

Debug.Print "number of tables (total) = " & db.TableDefs.Count
' number of user table
j = 0
For i = 0 To db.TableDefs.Count - 1
' Debug.Print db.TableDefs(i).Name
If Left(db.TableDefs(i).Name, 4) <> "MSys" Then
j = j + 1
End If
Next i
Debug.Print "number of tables (user) = " & j

Debug.Print "number of modules = " &
db.Containers("Modules").Documents.Count

' number of user queries
j = 0
For i = 0 To db.QueryDefs.Count - 1
If Left(db.QueryDefs(i).Name, 1) <> "~" Then
j = j + 1
End If
Next i

Debug.Print "number of Queries = " & j

End Function
 
V

Van T. Dinh

If you want a list of Form names, you can use a Query like:

SELECT MSysObjects.Name
FROM MSysObjects
WHERE (((MSysObjects.Type)=-32768));
 
Top