Is Your Access Form Open

Whether you're working with event procedures or function procedures, most form-modifying code will return an error if that form is open in Design View instead of Form View. However, there's an easy way to make sure the form is open in Form View before you execute any of those changes to your form via code. The following procedure returns the Boolean value True if a form is open in Form View and False if that form is open in Design View.

Function ObjectState(name As String) As Boolean
ObjectState = Forms(name).CurrentView <> 0
MsgBox ObjectState
End Function

We included the MsgBox statement so you can test the procedure. Open any form in Design View and run the function by entering the statement

ObjectState("yourformname")

in the Debug window. Access will display the word False in a message box. Now, open the form in Form View and try again. This time, Access will display the word True in a message box. When you include this function in your code, you'll probably want to omit the MsgBox statement.

You can also use the CurrentView property to determine how a data access page is displayed.

Access Index

Main Index

Search RD Techbase