Determining Parent form during runtime

  • Thread starter Thread starter KK
  • Start date Start date
K

KK

I have inherited an ADP project that implements a dynamic form loading
interface. When the app is started, the startup form displays with several
choices. WHen a choice is clicked, the main form gets out of the way (but is
still open) and the appropriate subform is dynamically loaded.

My problem is that whenever I want to debug a subform, or make any
modifications, I can't seem to ascertain just what the form-subform
hierarchy is.

Is there a way to add a control on any given form that will display the
complete "path" of up-level forms?

I appreciate any assistance on this.

Thanks,

Kevin
 
I'm not sure that you're actually using a subform in the sense that I
understand the word, that is to say a form that is displayed in a subform
control within the body of another form. Your description leads me to think
that you may be opening one form from another?

If you are using subforms as described above, then you can use the Parent
property something like this ...

Private Sub cmdTest_Click()

On Error Resume Next
Me.lblTest.Caption = Me.Parent.Name
Select Case Err.Number
Case 0
'Do nothing.
Case 2452
Me.lblTest.Caption = "I'm not currently being used as a subform"
Case Else
MsgBox "Error " & Err.Number & Err.Description
End Select

End Sub

If you are not using subforms, but opening one form from another, you can
use the OpenArgs argument of the OpenForm method to pass the name of the
calling form ...

From the calling form ...

Private Sub cmdCall_Click()

DoCmd.OpenForm "frmCallee", , , , , , Me.Name

End Sub

From the called form ...

Private Sub Form_Open(Cancel As Integer)

If Not IsNull(Me.OpenArgs) Then
Me.lblTest.Caption = "I was called by " & Me.OpenArgs
Else
Me.lblTest.Caption = "I don't know who called me."
End If

End Sub
 
Brendan, thanks for the suggestions. The cmdTest routine does show a parent
form, and the OnOpen event logic you suggested shows that it doesn't know
who opened it.

The parent form (frmNavigation) is dynamically loading subforms based on
what command button was clicked. In design mode, the automatic object and
property picker doesn't always work, since the subform isn't actually loaded
into the parent form until runtime. This makes it difficult to modify the
business logic on the form, especially when I need to reference objects
between two open forms.

Is there a way to overcome this design-time issue?

Thanks,

KK
 
I'm afraid I'm not sure I understood that. Perhaps if you could clarify the
following points, either I or someone else might be able to offer more help
....

a) When you say 'dynamically loading subforms' do you mean changing the
SourceObject property of a subform control?

b) What do you mean by 'automatic object and property picker'? What is it
that you are trying to do, and what problem are you experiencing when you
try?
 
Back
Top