August 18, 2008
How to reference an Access subform
- Date: July 28th, 2008
- Author: propecia gynecomastia Susan Harkins
One of the most common mistakes I see, and hear about it, is improper syntax when referencing controls on a subform. As far as Access is concerned, a subform is just another control on the main form — and that’s what confuses folks.
First, let’s review referencing controls in general. Use either of the following syntax statements to reference a control on a main form:
Forms!formname!controlname
Me!controlname
(In more recent versions, you can substitute bang (!) with dot (.) between objects.)
To refer to a subform or a control on a subform, you must remember that Access treats the subform as a control. Essentially, you have a form with a control with a control. To express that arrangement in terms Access can decipher, you need the Form property as follows
Forms!mainform!subform.Form.controlonsubform
Me!subform.Form.controlonsubform
In other words, subform is simply a control on the main form.
What I commonly see is a simple transposition of the Form property and subform, which generates a runtime error:
Forms!mainform.Form.subform.controlonsubform
In this form, Access assumes Form is a control. When it can’t find a control named form, Access returns an error.
Leave a comment
You must be logged in to post a comment.