Microsoft

How to reference an Access subform


Referencing subform controls always throws Access users for a loop while they're new to using Visual Basic for Applications (VBA). That's because Access views the subform as just another one of the form's controls.

To refer to a form, identify the form via the Forms collection as follows:

Forms!formname

Reference specific controls and subforms via the form's Controls collection:

Forms!formname!subformname

The subform is actually a control, but it's a control with dependent controls. That means you must identify both levels: the subform and the subform's controls. To do so, use the subform (control's) Form property in the form:

Forms!formname!subformname.Form.controlname

If the object name contains spaces, you must enclose any instance in brackets:

Forms![form name]![control name].Form.[control name]

In addition, you can use the Me identifier when the form is current, as follows:

Me!subformname.Form.controlname

About

Susan Sales Harkins is an IT consultant, specializing in desktop solutions. Previously, she was editor in chief for The Cobb Group, the world's largest publisher of technical journals.

1 comments
pascal3
pascal3

I had problems referencing subforms. I wanted to take a value from subform1 and use it to pass a value to a control (for example Name) in subform2. The problem was confused because the subforms were in a Parent form I had 'planted' onto a Navigation page. 

The code that works is:

Name = Forms!NavigationForm!NavigationSubform!subform1.Form.value

I didn't need to make reference to the Parent form because it was 'on' the Navigation subform.

I've shared this because the relief I feel needs sharing!!! It's also my first ever post.