How to determine source of opened form

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

Guest

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.
 
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.
 
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.
 
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.
 
Back
Top