Check whether a particular Form is Open

G

Guest

I need to be able to check in my code whether a particular Form is currently open. How do I do it?

Sometimes I need to be able to check whther certain Sub-Forms are also currently the SourceObject in certain Master Forms. I know how to check what the SourceObject is - once I know whether the Master form is Open, but is there a way I can tell from the Forms collection whether a Sub-Form is being used - without first checking the Master Form. (My system redefines which Sub-Forms are used in the same Control by switching the SourceObject.)
 
A

Allen Browne

The Northwind sample database includes an IsLoaded() function in the Utility
module.

The more recent versions of Access have an AllForms collection, with an
IsLoaded property, so you can use:
CurrentProject.AllForms("MyForm").IsLoaded

Neither of those approaches give information about subforms.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Brian McGuigan said:
I need to be able to check in my code whether a particular Form is
currently open. How do I do it?
Sometimes I need to be able to check whther certain Sub-Forms are also
currently the SourceObject in certain Master Forms. I know how to check
what the SourceObject is - once I know whether the Master form is Open, but
is there a way I can tell from the Forms collection whether a Sub-Form is
being used - without first checking the Master Form. (My system redefines
which Sub-Forms are used in the same Control by switching the SourceObject.)
 
J

John Vinson

is there a way I can tell from the Forms collection whether a Sub-Form is being used - without first checking the Master Form.

The Forms collection only contains open forms. If the form isn't open
it won't be in the collection (it will be in the Application's
Documents collection).
 
G

Guest

Thought everyone would like to know the following worked fine

Public Function FormIsOpen(FormName As String) As Boolea
' Written by: Brian McGuiga
' of: On2it Software Lt
' Version: 1.0
' Dated: 3/2/0
' Status: Teste

' Purpose: This function reads the AllForms Collection to determine whether a prticula
' named Form is Open
' If the FORM is OPEN the function returns a TRUE
' If not it returns a FALSE


Dim obj As AccessObject,
dbs As Objec

Set dbs = Application.CurrentProjec

If (dbs.AllForms(FormName).IsLoaded) The
FormIsOpen = Tru
Els
FormIsOpen = Fals
End I


End Functio

Public Function EntitySubForm() As Strin
' Written by: Brian McGuiga
' of: On2it Software Lt
' Version: 1.0
' Dated: 3/2/0
' Status: Teste

' Purpose: This Function returns the name of the currently loaded Sub-Form in th
' Forms!Entities!Entity.For
' If the "Entities" Form is not Open an empty string "" is returne

If (FormIsOpen("Entities")) The
EntitySubForm = Forms!Entities!Entity![Entity - Sub Form].SourceObjec
Els
EntitySubForm = "
End I

End Functio

Thanks for your advice.
 
D

david epsom dot com dot au

The Northwind sample database includes an IsLoaded() function in the
Utility

or
=SysCmd(SYSCMD_GETOBJECTSTATE, A_FORM, "frmRP_UserReports") in any version.

(david)
 

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