Loop through Forms collection and debug.print Forms Recordsource

Posted on 2004-08-17
Last Modified: 2012-06-27
I need to ba able to run some code that loops through all the form objects I have in my Access 2000 database, and pull out the name of the recordsource used by that form.  Any help much appreciated.

Question by:Philbee
  • 2
  • 2
LVL 39

Accepted Solution

stevbe earned 125 total points
ID: 11820051
what version of Access do you have?

Public Function DebugRS()
    Dim frm As AccessObject
    For Each frm In AllForms
        DoCmd.OpenForm frm.Name, acDesign
        Debug.Print Forms(frm.Name).RecordSource
        DoCmd.Close acForm, frm.Name, acSaveNo

End Function


Expert Comment

ID: 11820092
This one is the same, but works with versions before 2000:

Public Sub ListFormSources()
Dim frm As Form
Dim db As Database
Dim i As Integer
Dim FormName As String

Set db = CurrentDb()
For i = 0 To db.Containers("Forms").Documents.count - 1
    FormName = db.Containers("Forms").Documents(i).Name
    DoCmd.OpenForm FormName, acDesign
    Set frm = Forms(FormName)
    Debug.Print frm.Name & " RecordSource = " & frm.RecordSource
    DoCmd.Close acForm, FormName
Next i

End Sub

Author Comment

ID: 11820093
Thanks for that.  Almost got it myself.
LVL 39

Expert Comment

ID: 11820143
you may need to change AllForms to


you could also get this from the DOcumenter ...

Tools --> Analyze --> Documenter


Author Comment

ID: 11820158
Cheers, made the adjustments myself.  Thanks again

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The first two articles in this short series — Using a Criteria Form to Filter Records ( and Building a Custom Filter ( — discuss in some detail how a form can be…
Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now