Link to home
Start Free TrialLog in
Avatar of dsoderstrom
dsoderstrom

asked on

returning form properties using vba

Is there a way, using VBA, to read through the list of forms in an Access database and return the setting for a specific property?  Specifically I would like to see what the MinMaxButtons property is set to on each form in the database
Avatar of crystal (strive4peace) - Microsoft MVP, Access
crystal (strive4peace) - Microsoft MVP, Access

yes, you can run the free Analyzer here:

https://github.com/strive4peace/Analyzer

and then make a query using the a_Forms1 table with:

  • f_Name
  • f_MinMaxButtons

If you have only analyzed one database, you will not need to filter the query for DbID (assigned each time an analysis is done).

have an awesome day,
crystal
This will print out that specific property for all forms in the database.
Sub sDisplaySpecificProperty()
    Dim db As DAO.Database
    Dim ctr As Container
    Dim doc As Document
    Dim frm As Form
    Set db = DBEngine(0)(0)
    Set ctr = db.Containers!Forms
    For Each doc In ctr.Documents
        DoCmd.OpenForm doc.Name, acDesign, , , , acHidden
        Set frm = Forms(0)
        Debug.Print frm.Name & " -- " & frm.MinMaxButtons
        frm.ShortcutMenu = False
        DoCmd.Close acForm, doc.Name, acSaveYes
    Next doc
End Sub

Open in new window

Avatar of dsoderstrom

ASKER

Pat,
   I am trying to run your code and it's not working quite right.
   First, I took out the line "frm.ShortcutMenu = False" and I changed the Docmd.Close from acSaveYes to acSaveNo.  I don't want to modify anything.
   The problem I have is on the "Set frm = Forms(0).  After executing this line I'm thinking that the frm.name on the following line should match the doc.name on the preceding line but it does not.  frm.name is the name of a form but it does not match the doc.name.
I didn't write the code.  I modified it to print out the specific property you wanted to see.

There is a bug and I'll see if I can figure it out.  It looks like when you run it the first time, you get a bogus list but if you run it a second time, the list is correct.  Try that for now and I'll look at the code.  I thought the bug was fixed once I got a good list.  I never closed the app and then reopened it and tried again.  It is a problem only the first time you run it.

The save property was set because the original code actually modified form properties so rather than removing the line of code, comment it out so it will jog your memory if you want to convert this to actually changing the property.
ASKER CERTIFIED SOLUTION
Avatar of PatHartman
PatHartman
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks Pat.  It works perfectly now.
And thanks Crystal for the link to the Analyzer.  I will be taking a closer look at it when I get a chance.