Intrinsically retrieve calling form name

  • Thread starter Thread starter XP
  • Start date Start date
X

XP

Using Office 2003 and Windows XP;

I have a color coded control on a form that when double clicked opens a
popup, which is actually another form in datasheet view that acts as a pick
list. This keeps my main form clean and provides a nice interface.

Currently, I pass the name of the calling form and control to the pick list
form using OpenArgs. But, I was wondering whether there might be an intrinsic
way to obtain the calling form name and or control without actually having to
physically pass them? i.e. Just a line of code that retrieves this
information?

I'm not sure whether that can be done like this, but you don't know unless
you ask.

Thanks much in advance.
 
XP said:
Using Office 2003 and Windows XP;

I have a color coded control on a form that when double clicked opens a
popup, which is actually another form in datasheet view that acts as a
pick
list. This keeps my main form clean and provides a nice interface.

Currently, I pass the name of the calling form and control to the pick
list
form using OpenArgs. But, I was wondering whether there might be an
intrinsic
way to obtain the calling form name and or control without actually having
to
physically pass them? i.e. Just a line of code that retrieves this
information?

I'm not sure whether that can be done like this, but you don't know unless
you ask.

Thanks much in advance.


No, there isn't anything built in to do that. Using the OpenArgs property as
you describe is the standard way to handle it.
 
XP said:
Using Office 2003 and Windows XP;

I have a color coded control on a form that when double clicked opens a
popup, which is actually another form in datasheet view that acts as a
pick
list. This keeps my main form clean and provides a nice interface.

Currently, I pass the name of the calling form and control to the pick
list
form using OpenArgs. But, I was wondering whether there might be an
intrinsic
way to obtain the calling form name and or control without actually having
to
physically pass them? i.e. Just a line of code that retrieves this
information?

I'm not sure whether that can be done like this, but you don't know unless
you ask.


It's my habit to pass such information via OpenArgs, for maximum reliability
and flexibility. That said, you can, in my experience, get the calling
form's name, or an object reference to that form, in the called form's Open
event. At that point in the called form's lifetime, it is not yet the
active form. Therefore, you can do this:

'----- start of example code -----
Private Sub Form_Open(Cancel As Integer)

Dim frmCaller As Access.Form

On Error Resume Next ' ignore errors for this
Set frmCaller = Screen.ActiveForm

If frmCaller Is Nothing Then
MsgBox "Hey, what happened? There's no calling form!"
Else
' Get and act on calling form and control ...
Debug.Print frmCaller.Name
Debug.Print frmCaller.ActiveControl.Name
Debug.Print frmCaller.ActiveControl.Value
End If

On Error GoTo Err_Handler ' restore normal handling

' ... Rest of code goes here ....


Exit_Point:
Set frmCaller = Nothing
Exit Sub

Err_Handler:
' This would be your normal error-handling code,
' not necessarily what I show here.
MsgBox Err.Description, vbExclamation,, "Error " & Err.Number
Resume Exit_Point

End Sub
'----- end of example code -----
 
Back
Top