Microsoft Office Tutorials and References
In Depth Information
Understanding Objects and Collections
Seeing whether a form is open
You can create a custom VBA function that uses a collection and an object
variable. You can prevent your code and macros from opening multiple
copies of a form. The name of this custom function is isOpen(), as shown
in Figure 4-8.
form is open.
The isOpen() function is stored in a standard module rather than a class
module, so you can access it freely from anywhere in your database.
You use the isOpen() custom function just as you would a built-in function
by passing a form name to the function, as follows:
When called, the isOpen() function returns True if the specified form is
open or False if the specified form is closed. The first statement of the
isOpen() function is
Function isOpen(FormName As String) As Boolean
which defines the name of the function as isOpen, accepting a single string
value that is referred to as FormName within the procedure. This custom
function returns either True or False (a Boolean value).
The ByVal keyword, used in front of an argument name in a Sub or Function
statement, passes the value directly instead of as a reference to the object.
ByVal, although optional, can speed processing.
The next line sets the initial value to be returned by the function to False.
Later code in the procedure turns that value to True if the form is open in
Form or Datasheet view:
isOpen = False