Trying to convert an AccessObject to a Form

  • Thread starter Thread starter bill.parrott
  • Start date Start date
B

bill.parrott

I am using Access 2003/2007 and I am looping over the AllForms
collection. I need to examine a property of a Form that is not
available to a AccessObject. Is there a solution? My code is below:

Dim O as AccessObject
For Each O in CurrentProject.AllForms
msgbox O.tag <-- tag is not available to AccessObject
Next
....

Thanks
 
I think you will have to OPEN the form (in design view) in order to
check any of the form's properties.

'====================================================
John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
'====================================================
 
I am using Access 2003/2007 and I am looping over the AllForms
collection. I need to examine a property of a Form that is not
available to a AccessObject. Is there a solution? My code is below:

Dim O as AccessObject
For Each O in CurrentProject.AllForms
msgbox O.tag <-- tag is not available to AccessObject
Next
...

Thanks


As John says, you will have to open the form, as a form, to access
properties of the form. You can, however, add your own custom property to
the AccessObject. Here's an example that adds a property then uses the value
of that property as the caption of a label on the form ...

Public Sub TestAddProp()

Dim aob As AccessObject

Set aob = CurrentProject.AllForms("frmTest")
aob.Properties.Add "TestProp", "Hello World!"

End Sub

Private Sub Form_Load()

Me.lblTest.Caption =
CurrentProject.AllForms(Me.Name).Properties("TestProp")

End Sub

Last time I looked at the documentation on the AccessObject, it stated that
attempting to add a property that already existed would cause a run-time
error. It doesn't. It changes the value of the existing property.
 
As John says, you will have to open the form, as a form, to access
properties of the form. You can, however, add your own custom property to
the AccessObject. Here's an example that adds a property then uses the value
of that property as the caption of a label on the form ...

Public Sub TestAddProp()

    Dim aob As AccessObject

    Set aob = CurrentProject.AllForms("frmTest")
    aob.Properties.Add "TestProp", "Hello World!"

End Sub

Private Sub Form_Load()

    Me.lblTest.Caption =
CurrentProject.AllForms(Me.Name).Properties("TestProp")

End Sub

Last time I looked at the documentation on the AccessObject, it stated that
attempting to add a property that already existed would cause a run-time
error. It doesn't. It changes the value of the existing property.

I did some digging and found a snippet of code that helped. The form
does in fact need to be opened, and here's what I did:

Dim A As AccessObject
Dim F As Form

For Each A In CurrentProject.AllForms
If A.Name <> Me.Name Then
DoCmd.OpenForm A.Name, acViewDesign, , , , acHidden
SetFormVersion A.Name, Forms(A.Name).Tag
DoCmd.Close acForm, A.Name
End If
Next

I like being able to create a property programatically (which will
help with the form template I'm building). Thanks for the tip.
 
Back
Top