Tips Index

Microsoft Access Tips and Tricks

How to Get a Reference to a Subform's Parent Control

When you are writing code for a subform, it's easy to get a reference to the parent form that holds the subform. In the subform's class module, you just refer to the Parent property; for example,

Select Case Me.Parent.Name
        Case "frmOne"
            ' Do one thing.
        Case "frmTwo"
            ' Do another thing.
        Case "frmThree"
            ' Do something else altogether.
     End Select

But how do you get a reference to the subform *control*, on that parent form, that contains the subform on which the code is running? You might want to resize or highlight that control from one of the events of the subform, or if you are using the same form object as a subform multiple times on a parent form, you might need to know exactly which of the subform controls is displaying the active instance of the subform.

The following, when passed a reference to the subform's form object, will return a reference to the subform control on the parent form that contains that subform:

code: click in the frame, Select All, then Paste into your code editor

You would most likely call that function from the code module of a subform using code like this:

code: click in the frame, Select All, then Paste into your code editor

Relevance: Microsoft Access
Versions: Access 95 to 2007
Categories: VBA, How To, Forms, Subforms, Utility Functions
Date: 13 May 2009

Tips Index