Controls on a form:
Forms!frmMain!txtControlName
Forms!frmMain!txtControlName.enabled = TrueControls on a Sub form:
Forms!frmMain!Subform1.Form!txtControlName
Forms!frmMain!Subform1.Form!txtControlName.enabled = TrueIf the name is unique, shortcut naming will also work, so the above can be simplified to:
Forms![frmMain]![Subform1]![txtControlName]
To refer to other control properties replace .enabled with the property name you need.
The default property is always .value (you can include .value if you want to make this absolutely clear.)
Properties of the whole FORM:
Forms!frmMain.RecordSource
e.g. Forms!frmMain.RecordSource = “select * from my_table;”
Properties of a whole Sub form:
Forms!frmMain!Subform1.Form.RecordSource
To refer to other form properties replace .RecordSource with the property name you need.
Controls on a form:
Me!txtControlName
Controls on a Sub form:
Me!Subform1.Form!txtControlName
Me!Subform1.Form!txtControlName.enabled = TrueControls on a Parent form:
Me.Parent!txtControlName
In these examples txtControlName is whatever name you have given the control e.g. txtSurname
To refer to other control properties replace .enabled with the property name you need.
e.g. txtControlName.Visible or txtControlName.BackColor
Properties of the whole FORM:
Me.RecordSource
Properties of a Sub form:
Me!Subform1.Form.RecordSource
Refer to properties of a Parent form:
Me.Parent.RecordSource
To refer to other form properties replace .RecordSource with the relevant property name.
Nesting a subform inside another subform is rare, but for the sake of completion..
For these examples Subform1 is the name of a subform control on frmMain, Subform2 is the name of another subform control placed on Subform1. The name of form controls need not be the same as the name of the forms.
Controls on a nested Sub-Sub form:
Forms!frmMain!Subform1.Form!Subform2.Form!txtControlName
Me!Subform1.Form!Subform2.Form!txtControlNameProperties of a nested Sub-Sub form:
Forms!frmMain!Subform1.Form!Subform2.Form.RecordSource
Me!Subform1.Form!Subform2.Form.RecordSourceThe parent of a Parent:
Me.Parent.Parent!txtControlName
Me.Parent.Parent.RecordSource
Using a relative reference on a form ensures that nothing will break if the form is renamed.
If you are writing an expression as part of an SQL statement, then use an absolute reference.
An alternate syntax for VBA only, is written like: Forms("frmMain").ControlName
This syntax is allows you to use a variable in an identifier.
Related
Q209207 - Command-line switches for MS Access
Microsoft Office online - Referring to an object or its properties in expressions