Subforms, subforms, subforms…
For many Access developers, even experienced ones, that word can be intimidating. How do you point to a control on a subform? How do you reference a subform so you can requery it? And how do you reference a subform in order to requery a control that lives on it?
Well, you can stop worrying. I’ll walk you through how to EASILY remember the way subforms work and how to reference them. It took me nearly ten years to grasp it, and my hope is that it will take you only about ten minutes once I’ve finished explaining.
WHEN IS A SUBFORM NOT REALLY A SUBFORM?
When most people start out with Access, they assume that clicking the subform/subreport button simply places their subform on the main form. That’s partly true. What they often miss is that the subform actually lives inside something else: a control that sits on the main (or PARENT) form and acts as the interface between the two forms. In other words, it HOUSES the subform.
Because the subform control is essentially the interface between the main form and the subform, your code needs a way to tell the main form which object you mean. One key point: the subform control and the subform itself can share the same name. In fact, naming them the same can make things a bit easier, since you won’t have to hunt down the control name when you already know the subform name. That said, they don’t have to match.
KEY CONCEPT: When you refer to a subform on a main form, you use the CONTROL NAME (the screenshot labels it “CONTAINER”, but it is the subform control), not the subform name. Keep that in mind, because it’s important and it’s a common reason people can’t figure out why their code isn’t working.
How Do You Refer to a Form Inside the Subform Container?
In Access, objects have properties and methods, and there are two things to keep in mind. First, when you want a property or method on the CONTROL, you simply refer to the subform CONTROL. But if you want a property or method on the subform itself, you have to tell Access you mean the form, not the subform control. How? You use the word FORM. Simple, right? You need the word FORM whenever you want a property or method of the subform.
So if the word FORM refers to the actual form inside the subform control, how do you refer to a control on the subform? Logically, you need to tell Access you mean a control on the subFORM itself, not on the control (which has no controls). That means you need the subform CONTROL name, the word FORM, and the control name. The reference would look like MySubformControlName.Form.MyControl. But we’re not done yet; there are a couple more concepts to cover before you’re ready to tackle it.
Next, determine whether your code lives in the subform or on the main form. If it’s on the main form (and code in an event on the subform CONTROL counts as being on the main form), you can use the shortcut keyword ME to refer to the main form. So Me.MySubformControlName.Form.MyControl would be the reference from code on the main form. If the code is on the subform, it becomes simply Me.MyControl, since it refers to items on the form where the code resides.
If you need to refer to another form, you can use this approach, which I’ll admit is a bit confusing:
Forms!YourMainFormName.YourSubformControlName.Form.YourControlName
I call it confusing because it works fine for one level, but imagine a subform nested four levels deep. In other words, a form with a subform with a subform with a subform with a subform. That can be a nightmare to work out. But I said you can remember how to do this because there’s an easier pattern. Instead of Forms!, use Forms() to pull the form from the forms collection. If our main form is named “frmTest”, we’d use Forms(“frmTest”). Next, since we know the subform container is a control, use the CONTROLS collection with Controls(“MyControlName”). Put those together and we have:
Forms(“frmTest”).Controls(“MySubformControlName”)
Then we need to refer to the control on the subform itself. Remember, we have to tell Access that we want the form and the control on that form. That means we would use
Forms(“frmTest”).Controls(“MySubformControlName“).Form
and then we have to add the control we want to reference and that control is in the subform’s controls collection, so it is just another instance of .Controls(“controlname”) which will get us to our location. So the result is:
Forms(“frmTest”).Controls(“MySubformControlName“).Form.Controls(“MyControlName”
Now, what should you remember when referring to a control on a subform this way? If you want a property or method, you must use it explicitly, because there’s no default with this syntax. So if we wanted the value of MyControlName, we’d need to use:
Forms(“frmTest”).Controls(“MySubformControlName“).Form.Controls(“MyControlName”).Value
But you say,.”that is so long compared to the other”, as we shared above:
(as above): Forms!YourMainFormName.YourSubformControlName.Form.YourControlName
Yes, it is a little longer in typing the one with Forms(“frmTest”) … etc., out. However, the ease of remembering the pattern is what will help you. Because, you can substitute variables for the names of the forms and controls but the syntax is exactly the same. So, if I was referring to a form variable of strForm and a subform of strSubForm and a text box on the subform of strControl then I would refer to it this way:
Forms(strForm).Controls(strSubform).Form.Controls(strControl).Value
with no special syntax change required. And for the four levels deep subform, it would be easy to do with:
Forms(“MainFormName”). Controls(“MySubformControlName“). Form.Controls(“SubformControl2”). Form.Controls(“SubformControl3”). Form.Controls(“SubformControl4”). Form.Controls(“MyTextBox”).Value
So, hopefully that helps you with understanding how to reference subforms. The concept is just slightly different for referencing subforms within control sources but we will cover that in another tutorial.

