Event? to know when form is already open in background

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
 
D

Dirk Goldgar

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
 
J

JohnR

Try this function

Function IsLoaded(ByVal strFormName As String) As Boolean
' Returns True if the specified form is open in Form
view or Datasheet view.
Dim oAccessObject As AccessObject

Set oAccessObject = CurrentProject.AllForms
(strFormName)
If oAccessObject.IsLoaded Then
If oAccessObject.CurrentView <> acCurViewDesign
Then
IsLoaded = True
End If
End If

End Function

Then add the following code:
If Isloaded(TheFormTheyAreTryingToLoad) then
msgbox "The form is open in the BackGround"
Exit Sub
End IF
 
P

P

Thank you JohnR. This helps. P

JohnR said:
Try this function

Function IsLoaded(ByVal strFormName As String) As Boolean
' Returns True if the specified form is open in Form
view or Datasheet view.
Dim oAccessObject As AccessObject

Set oAccessObject = CurrentProject.AllForms
(strFormName)
If oAccessObject.IsLoaded Then
If oAccessObject.CurrentView <> acCurViewDesign
Then
IsLoaded = True
End If
End If

End Function

Then add the following code:
If Isloaded(TheFormTheyAreTryingToLoad) then
msgbox "The form is open in the BackGround"
Exit Sub
End IF
 
P

Pieter Linden

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top