Object Variables

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

In a called module (not bound to a form)I use the following to create Object
Variables to reference objects on a form. Do I have to define them in each
module or can I define them once in a public module and use the reference in
all modules as needed? If I do that when is the reference compiled?

Dim frmEntry As Form
Dim subFrmEntry As Form

Set frmEntry = [Forms]![Indvl Entries]
Set subFrmEntry = frmEntry![Entries Subform].[Form]

Steve S.
 
Hi,
yes, you can declare these form variables in a module and then use
everywhere in your app, but make sure your form in opened. Not sure what you
mean on "when is the reference compiled" - once you set such public variable
to a form - it will hold reference until form will be closed.

--
Best regards,
___________
Alex Dybenko (MVP)
http://alexdyb.blogspot.com
http://www.PointLtd.com
 
It is possible, but I wouldn't do it.
Your code would not do it correctly, even in a standard module. The Dim
needs to be at the module level, not the procedure level. Also, the form has
to be open or it will raise an error. And, if you close the form, the object
variable will loose it's value.

Option Compare Database
Option Explicit

Public frmEntry As Form
Public subFrmEntry As Form

Public Sub SetFormRefs()
Set frmEntry = [Forms]![Indvl Entries]
Set subFrmEntry = frmEntry![Entries Subform].[Form]
End Sub
 
Back
Top