Determine if form is open

F

Flick Olmsford

I have two forms - FORMA and FORMB - that I have not linked. I want to
place a command button on FORMB that causes it to set a control in FORM B to
a person's id currently showing in FORMA. Or to automatically set FORM B to
show a record in FORMB related to the record in FORMA upon opening.

I know how to set the value but ...

How do I determine if FORMA is open from inside a module in FORMB?
 
F

fredg

I have two forms - FORMA and FORMB - that I have not linked. I want to
place a command button on FORMB that causes it to set a control in FORM B to
a person's id currently showing in FORMA. Or to automatically set FORM B to
show a record in FORMB related to the record in FORMA upon opening.

I know how to set the value but ...

How do I determine if FORMA is open from inside a module in FORMB?

What version of Access?
Access 2000 or newer?

If Not CurrentProject.AllForms("FormA").IsLoaded Then
' FormA is not open
Do something here
Else
' FormA is open
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
'FormA is not open
Do this
Else
'FormA is open
Do that
End if
 
J

Jeff Boyce

Why? You've described "how" you are trying to do something (using two
forms, checking between them). Unless you also provide some specifics of
"what" you are trying to do, you won't get the full benefit of having all
these folks here in the newsgroup. It may be that there are alternate ways
to get done what you want to, if only we knew what that was...

--
Regards

Jeff Boyce
www.InformationFutures.net

Microsoft Office/Access MVP


Microsoft IT Academy Program Mentor
http://microsoftitacademy.com/
 
F

Flick Olmsford

Thank you very much.




fredg said:
What version of Access?
Access 2000 or newer?

If Not CurrentProject.AllForms("FormA").IsLoaded Then
' FormA is not open
Do something here
Else
' FormA is open
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
'FormA is not open
Do this
Else
'FormA is open
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

Top