This article describes you how to add a text box control to an Access form, and then set the properties for that text box so that it displays a value from a control on another form. This is useful in the following situations:
-
You have a main form that contains a subform; the subform contains a calculated text box (for example, a total of item prices), the results of which you want to display on the main form.
-
You have a form that contains a command button that opens a second form, and you want a text box on the second form to display the value of a control on the first form.
Create the control
-
In the Navigation Pane, right-click the form that you want to change, and then click Design View or Layout View.
-
On the Design tab, in the Controls gallery, click Text Box.
-
Click in the form where you want to create the text box.
-
Make sure that only the text box is selected. If necessary, click a different control, and then click the text box again.
-
If the property sheet is not already displayed, right-click the text box and then click Properties.
-
In the Property Sheet task pane, click the All tab.
-
Set the Control Source property using the following syntax:
=[Forms]![form name]![control name]
Where form name is the name of the form that contains the control whose value you want to display, and control name is the name of the control.
Referencing a control on a subform is a bit more complicated. In those cases, use syntax like the following:
=[Forms]![main form name]![name of the subform control on the main form].[Form]![control name on the subform]
Where main form name is the name of the main form, name of the subform control on the main form is the control name on the main form that is the container for the subform, and control name on the subform is the name of the control on the subform that contains the control whose value you want to display.
Note: In all cases, the form you want to reference must be open in order for Access to read its value. The form can be hidden, but it must be open.
Examples
Example 1: Reference other form
Suppose that you have a main form named Orders and you want to display the value of a control called First Name that is on a form called Employee Details. To display the value from the First Name control on the Employee Details form, you would add a text box to the Orders form and specify its Control Source property as follows:
=[Forms]![Employee Details]![First Name]
Example 2: Reference a control on a subform from the main form
Suppose that you have a main form named Orders. This form contains a subform control named Orders Subform, and the subform contains a calculated text box named OrderSubtotal. To display the value from the OrderSubtotal control on the Orders main form, you would add a text box to the Orders main form and specify its Control Source property as follows:
=[Forms]![Orders]![Orders Subform].[Form]![OrderSubtotal]
Note: In all cases, the form you want to reference must be open in order for Access to read its value. The form can be hidden, but it must be open.
No comments:
Post a Comment