Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

ACC2000: How to Use the Parent Property of a Subform


View products that this article applies to.

This article was previously published under Q209539
Novice: Requires knowledge of the user interface on single-user computers.

This article applies to a Microsoft Access database (.mdb) and to a Microsoft Access project (.adp).

↑ Back to the top


Summary

This article describes how to use a subform's Parent property to return the name of its parent form.

↑ Back to the top


More information

The Parent property of a control refers to the control's Parent object. In the example below, we use the Parent property of a subform to determine the name of the main form.

The correct syntax for the Parent property in macro actions called from a subform is:
Forms![Main Form Name]![Subform ControlName].Form.Parent.Name
This expression can be simplified when we consider that the Form property is the default property for the subform control. The simplified form of the above expression then becomes:
Parent.Name
The following example demonstrates how to use the Parent property in a macro:
  1. Start Microsoft Access and open the sample database Northwind.mdb.
  2. Create and save the following macro:
    Macro: Get Parent Name
    ---------------------------------------------------------------
    Action: MsgBox
    Message: ="Parent: " & Forms.Orders![Orders Subform].Form.Parent.Name
    Title: Parent Form Name
    NOTE: You can substitute the simplified expression "Parent.Name" for the full expression used in this example.

  3. Open the Orders Subform form in Design view. Add the Get Parent Name macro to the OnDblClick event of the ProductID field:
    Object: Text Box
    --------------------------------------------------------------
    ControlName: ProductID
    OnDblClick: Get Parent Name
  4. Save and close Orders Subform.
  5. Open the Orders form. Double-click the ProductID field in the subform. Notice that the parent form name, Orders, is displayed in a dialog box.
  6. Close the Orders form. Open the Orders Subform form in Design view, and then remove the macro that you added in step 2.

↑ Back to the top


References

For more information about the Parent property, click Microsoft Access Help on the Help menu, type parent property in the Office Assistant or the Answer Wizard, and then click Search to view the topic.

↑ Back to the top


Keywords: KB209539, kbusage, kbhowto

↑ Back to the top

Article Info
Article ID : 209539
Revision : 2
Created on : 6/24/2004
Published on : 6/24/2004
Exists online : False
Views : 267