How to know if a Specific Form is Openned?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have several forms openned and I need to know if a spacific form is one of
them, even though it is not the active one.

Thanks a lot,
Lina
 
Hi,
This code is a straight copy from Northwind sample db. Place it in a module
and save.

Function IsLoaded(ByVal strFormName As String) As Boolean
On Error GoTo Err_IsLoaded

Dim oAccessObject As AccessObject

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

Exit_IsLoaded:
Exit Function

Err_IsLoaded:
Msgbox err.Description
Resume Exit_IsLoaded

End Function

Then, wherever you want to test whether a form is loaded, i.e., opened, you
can use this function like this:

If IsLoaded("frmMyForm") then ...........

This function returns a simple 'True' if the form is opened and 'False' if
not.

Hope that helps.
 
I have several forms openned and I need to know if a spacific form is one of
them, even though it is not the active one.

Thanks a lot,
Lina

What version of Access?
Access 2000 or newer?

If Not CurrentProject.AllForms("FormA").IsLoaded Then
Do something here
Else
Do something else
End If

In Access 97, copy this function (from the Northwind.mdb sample
database) into a module:

Function IsLoaded(ByVal strFormName As String) As Integer
' 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

Then code some event:
If Not IsLoaded("FormA") Then
Do this
Else
Do that
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

Back
Top