MS Access: Check if a form is loaded in Access 2003/XP/2000/97

It is often useful in Access programming to know whether a form is already loaded. To do this, you can use the function IsLoaded.

For example:

If CurrentProject.AllForms("Suppliers").IsLoaded = True Then

.

End If

This code checks to see if the form called Suppliers has been loaded in the current Access session.


Here is an example of how we've used IsLoaded.

Function GetCity() as string

If CurrentProject.AllForms("Suppliers").IsLoaded = True Then
GetCity = Form_Suppliers.txtSupplier_City
Else
GetCity = ""
End If

End Function

This function is used to retrieve the value of the txtSupplier_City in the Suppliers form.

If the Suppliers form is loaded, it will return the value in the textbox called txtSupplier_City. If the form is not loaded, it will return a blank value. This helps us avoid errors if we try to access the txtSupplier_City value when the Suppliers form is not loaded.

You can then use this function in a Query or a Report. or for that matter, anywhere within your Access database.