Retrieve list of forms in an Access database
Asked Answered
S

1

5

How can I retrieve a list of all forms in a MS-Access database?

To retrieve a list of all tables I use this:

For Each TDef In CurrentDb.TableDefs
    If Left(TDef.Name, 4) <> "MSys" And Left(TDef.Name, 7) <> "~TMPCLP" Then
        Debug.Print TDef.Name
    End If
Next

Also see this issue.

But I can't do this for forms.

Sloppy answered 20/7, 2012 at 9:12 Comment(0)
D
8

You can use AllForms for a list of names. These are not instances of forms, just names.

Sub ListForms()
Dim frm As Object
Dim LiveForm As Form

    For Each frm In CurrentProject.AllForms
        Debug.Print frm.Name
        ''To use the form, uncomment
        ''DoCmd.OpenForm frm.Name, acViewDesign
        ''Set LiveForm = Forms(frm.Name)
        ''Do not forget to close when you are done
        ''DoCmd.Close acForm, frm.Name
    Next
End Sub
Determinant answered 20/7, 2012 at 9:13 Comment(3)
I have to use Dim frm As AccessObject to make it runSloppy
And how can I retrieve the title of the Form? Debug.Print frm.Properties("Caption") doesn't workSloppy
You must first open the form to get additional details. AllForms is more or less a list and all you can get is (more or less) the name, creation date and whether it is loaded or not.Determinant

© 2022 - 2024 — McMap. All rights reserved.