How to find all the forms in an MS Access Database using VBA

This procedure finds all the forms in an MS Access Database. This shows how many forms are in the database and prints out the source of each form. In order to print the source of each form, the form should be opened in design mode.

Public Sub AllForms()
    Dim obj As AccessObject, dbs As Object
    Set dbs = Application.CurrentProject
    ' Search for open AccessObject objects in AllForms collection.
    MsgBox dbs.AllForms.Count
    For Each obj In dbs.AllForms
        'If obj.IsLoaded = True Then
            ' Print name of obj.
           ' Debug.Print obj.name & vbNewLine & "--------------"
           ' For Each prop In obj.Properties
            '    Debug.Print vbTab & prp.name & " = " & prp.Value
           ' Next
           DoCmd.OpenForm obj.Name
            Debug.Print obj.Name & " RecordSource -" & Forms(obj.Name).RecordSource
           DoCmd.Close acForm, obj.Name
        'End If
    Next obj
End Sub

This is a complimentary article written by the MAARS team for the MAARS user community. Code in this article drives the operation of MAARS (MS Access Application wRiting Software). MAARS is an intelligent automation program that speeds up MS Access Application Development by 10x, 20x or 100x times. To learn more about MAARS, click here.

Disclaimer:

Some information included in this article may have been sourced from other publicly available websites and blogs. In such cases, credit goes to those authors for the original ideas and thoughts, but we do take credit for putting valuable information together and improve the efficiency of other office developers.