Event? to know when form is already open in background

  • Thread starter Thread starter P
  • Start date Start date
P

P

Hi,

Access 2002. I use DoCmd.OpenForm attached to command buttons to open one
form from another form. All forms are open in dialog mode. When a user tries
to open a form already opened from a form in dialog mode, nothing happens as
expected. I would like to inform the users that the form does not open
because it is already opened in the background. What event do you suggest
using for this? Thank you. P
 
P said:
Hi,

Access 2002. I use DoCmd.OpenForm attached to command buttons to open
one form from another form. All forms are open in dialog mode. When a
user tries to open a form already opened from a form in dialog mode,
nothing happens as expected. I would like to inform the users that
the form does not open because it is already opened in the
background. What event do you suggest using for this? Thank you. P

There is no event, but you can check before calling DoCmd.OpenForm. In
Access 2000 or later, you can do it like this:

Dim strFormToOpen As String

strFormToOpen = "MyForm"

If CurrentProject.AllForms(strFormName).IsLoaded Then
MsgBox "That form is already open."
Else
DoCmd.OpenForm strFormToOpen, WindowMode:=acDialog
End If
 
Thank you Dirk. This helps. P.

Dirk Goldgar said:
There is no event, but you can check before calling DoCmd.OpenForm. In
Access 2000 or later, you can do it like this:

Dim strFormToOpen As String

strFormToOpen = "MyForm"

If CurrentProject.AllForms(strFormName).IsLoaded Then
MsgBox "That form is already open."
Else
DoCmd.OpenForm strFormToOpen, WindowMode:=acDialog
End If

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
Straight outta the help file....

CurrentProject.AllForms("frmGetHostName").IsLoaded

returns either True or False. How much easier could it get?

So you could create a function or something...

public function IsFormLoaded(byval strFormName as String) as boolean

IsFormLoaded =CurrentProject.AllForms(strFormName).IsLoaded

End Function

If IsFormLoaded("MyForm") Then
...
Else
DoCmd.OpenForm strForm
End If
 
Back
Top