How to determine source of opened form

M

Mary Fran

Hi! I have a procedure that I wish to run depending on which form was used to
open the existing form. How do I determine that or if a given form is open?
Thanks.
 
B

Brendan Reynolds

To determine whether a given form is open ...

If CurrentProject.AllForms("NameOfFormHere").IsLoaded Then
'it's open
Else
'it's not
End If

Access does not (so far as I am aware) expose any means to identify what
form or procedure opened the active form, so you'd need to keep track of
that yourself in some way, for example by passing the name of the calling
form in the OpenArgs argument of the OpenForm method or by using a global
variable.
 
M

Mary Fran

Thank you!

Brendan Reynolds said:
To determine whether a given form is open ...

If CurrentProject.AllForms("NameOfFormHere").IsLoaded Then
'it's open
Else
'it's not
End If

Access does not (so far as I am aware) expose any means to identify what
form or procedure opened the active form, so you'd need to keep track of
that yourself in some way, for example by passing the name of the calling
form in the OpenArgs argument of the OpenForm method or by using a global
variable.
 
D

Dirk Goldgar

Brendan Reynolds said:
To determine whether a given form is open ...

If CurrentProject.AllForms("NameOfFormHere").IsLoaded Then
'it's open
Else
'it's not
End If

Access does not (so far as I am aware) expose any means to identify
what form or procedure opened the active form, so you'd need to keep
track of that yourself in some way, for example by passing the name
of the calling form in the OpenArgs argument of the OpenForm method
or by using a global variable.

This is true, but you can, in the opened form's Open event, find out
what form is currently active by interrogating Screen.ActiveForm.Name,
which -- if this form can only be opened from another form -- will be
the "calling" form.

I prefer Brendan's approach of passing the name of the calling form via
OpenArgs, because it is insulated from any unexpected loss of focus by
the calling form.
 
Top