I have a switchboard with buttons to open other forms. Here is an example of
On Click code...
DoCmd.OpenForm ("frmCustomers")
Forms.Item("frmSwitchB").Visible = False
The form so opened has a 'return to switchboard button', cmdSwitch, with
code...
Me.Visible = False
Forms.Item("frmSwitch").Visible = True
Everything seems to be working as expected. But... when I click a button on
FrmSwitch, I don't really know if the form it is trying to open is already
open but just not visible. Does it matter? Does Opening a non-visible but
already open form just result in making it visible? (or am I opening the
form yet again, not knowing that I'm building up a collection of invisible
copies)
Mr B - 02 Mar 2007 22:39 GMT
Here is a function that will tell you if the form is already open:
Public 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
Just call the function like this:
If IsLoaded("frmYourFormName") Then
Forms![frmYourFormName].Visible = True
Else
DoCmd.OpenForm "frmYourFormName"
End If

Signature
HTH
Mr B
> I have a switchboard with buttons to open other forms. Here is an example of
> On Click code...
[quoted text clipped - 12 lines]
> form yet again, not knowing that I'm building up a collection of invisible
> copies)