Identify calling form

J

J. M. De Moor

Is it possible to identify which form opened a give form? In other words is
the call stack visible to VBA?

Thanks.
 
G

Graham R Seach

The call stack isn't available through VBA, but you can pass the calling
form's name via the OpenForm method's OpenArgs argument:
DoCmd.OpenForm "frmMyForm", , , , , , "frmCallingForm"

Retrieve the calling form's name using the Me.OpenArgs construct
Private Sub Form_Open(Cancel As Integer)
Dim sCallingForm As String

sCallingForm = Me.OpenArgs
MsgBox sCallingForm
End Sub

Regards,
Graham R Seach
Microsoft Access MVP
Canberra, Australia
 
D

Dirk Goldgar

J. M. De Moor said:
Is it possible to identify which form opened a give form? In other
words is the call stack visible to VBA?

As Graham pointed out, the call stack is not accessible. Graham's
suggestion of passing the name of the calling form via OpenArgs is
probably the most reliable and general. However, in the new form's Open
event, the calling form is still the "active form", as far as Access is
concerned, so you can also get a reference to it via the
Screen.ActiveForm method. That wouldn't be safe if some other form
might grab the focus between the time the OpenForm method was called on
the calling form and the time the called form's Open event checks
Screen.ActiveForm, or if the form might be opened by some form that is
not currently active.
 
G

Graham R Seach

<<...you can also get a reference to it via the Screen.ActiveForm method>>
I didn't know that! Thanks Dirk.

Regards,
Graham R Seach
Microsoft Access MVP
Canberra, Australia
---------------------------
 

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