Microsoft Office Tutorials and References
In Depth Information
Understanding Objects and Collections
The next line in the code declares an object variable named myForm and sets
its type to AccessObject:
Dim myForm As AccessObject
The next line makes the myForm object variable refer to the specific form,
based on the name that passes to the function:
Set myForm = CurrentProject.AllForms(strFormName)
If you call the function by using isOpen(“Products Form”), the variable
name myForm refers to the Products Form after the line is executed.
The next statement uses the built-in IsLoaded property to determine
whether the form is open. If the form is open, IsLoaded returns True. If the
form is closed, IsLoaded returns False.
If myForm.IsLoaded Then
If (and only if) the form is indeed open, the next statement uses the
CurrentView property to see whether the form is currently open in Design
view or Layout view. (CurrentView is a property of all form objects;
acCurViewDesign is a constant that means “currently open in Design
view”; acCurViewLayout is a constant that means “currently open in
Layout view.”)
If myForm.CurrentView <> acCurViewDesign And _ myForm.CurrentView <>
acCurViewLayout Then
If (and only if) the form is open — but not open in Design view or Layout
view — the following statement sets isOpen to True. If the form isn’t open
or is open in Design view or Layout view, the next line doesn’t execute, so
isOpen retains its original value of False.
isOpen = True
The rest of the procedure just contains an End If statement for each If
block and the End Function statement to mark the end of the procedure.
To see some practical uses of the custom isOpen() function, imagine that
you’ve already added that custom function to a standard module in your
database. Now you want to use the function to see whether a form is open
before you execute code to open that form. In particular, you want the code
to see whether Products Form is open — and, if it isn’t, to go ahead and
open the form. Use the following code to open a form:
‘Open Products Form, but only if it isn’t open already.
If Not isOpen(“Products Form”) Then
DoCmd.OpenForm “Products Form”
End If
Search JabSto ::

Custom Search