Paul,
The short answer is, "Yes," you can check to see if a
form is open.
I find that in some cases I may even open the same form
from different menus or from other forms. Therefore, I
would suggest that in those cases you can use
the "OpenArgs" argument when opening a form. Basically
this argument option lets you send information that you
can later check for, when you are opening a form. (Check
the help file to get more details on this.)
In any case, to check to see if a form is open, first
copy the function below to a module (not the module of a
form).
****** function code starts here ******
Function IsLoaded(ByVal strFormName As String) As Boolean
' Returns True if the specified form is open in Form
view or Datasheet view.
Const conObjStateClosed = 0
Const conDesignView = 0
If SysCmd(acSysCmdGetObjectState, acForm,
strFormName) <> conObjStateClosed Then
If Forms(strFormName).CurrentView <>
conDesignView Then
IsLoaded = True
End If
End If
End Function
****** end of function code ******
Next, in the OnClose event of any form, you can call the
function like:
****** code starts here ******
If Me.OpenArgs = "frmMainMeun" Then
If IsLoaded("frmMainMeun") Then
Forms!frmMainMeun.Visible = True
Else
DoCmd.OpenForm "frmMainMeun"
End If
End If
****** end of code ******
By the way, the first line of this code is only checking
to see if the from was opened from the Main Menu, having
used the "OpenArgs" argument. You could just as easily
use a Select Case statement to evaluate the value of
the "OpenArgs" if you knew that you were going to open
the same form from multiple calling locations.
If you only want to check to see if the "frmMainMenu"
form is open, then just remove the first "IF" statement
and it's "EndIF".
HTH
Byron