How to test whether a form is open

zorplex

New member
Local time
Today, 12:11
Joined
Feb 18, 2005
Messages
7
I have a form which needs to test whether another form is open and if not open it, otherwise sets its visibility to true and give it focus.

I can open the form using the DoCmd.OpenForm command but how do I test whether it is open in the first place?
 
Straight from the Dev Ashish site.

Forms: Find out if a form is open
Author(s)
Dev Ashish


(Q) How do I find out from code if a form is open or not?

(A) Pass the form name to the following function. Function will return True if form is open and False if it's not.

'****** Code Start ********
Function fIsLoaded(ByVal strFormName As String) As Integer
'Returns a 0 if form is not open or a -1 if Open
If SysCmd(acSysCmdGetObjectState, acForm, strFormName) <> 0 Then
If Forms(strFormName).CurrentView <> 0 Then
fIsLoaded = True
End If
End If
End Function
'****** Code End ********
 
zorplex said:
I have a form which needs to test whether another form is open and if not open it, otherwise sets its visibility to true and give it focus.

You should look at the Northwind database that comes with Access as it contains a function that does this.
 
Bill was kind enough to make the IsLoaded() function from the Northwinds into an IsLoaded Property for Access 2003.
 
If SysCmd(acSysCmdGetObjectState, acForm, "FormName") <> 0 Then

this is the important line.
 

Users who are viewing this thread

Back
Top Bottom