I am getting variable not defined, with this Form_Subform_Example1.txtbox2 = 3. I am trying point to a textbox on a subform from the main form. It highlights 3. What are some possible solutions or examples?
Hi. It highlights the 3 or the entire line? What is the name of the Textbox you're trying to point to. I don't normally use the Form_ syntax because it points to the Class Object. Rather, I often just use the Forms! syntax.
Form_formname should never be used to refer to a form. Refer to a form via the Forms Collection. Using Form_ often works but it is inviting trouble.
Always use Forms!formname or Forms("formname") unless you are directly referring to it from its Parent or one of its Members.
Contrary to a unfortunately too common belief, Form_ isn't just another syntactical variation of the Forms Collection but a reference to the form object via its Module. (You can verify this by referring to a form that does not have a Module. It will return an error, "External Name not defined".)
Moreover, if the Form is not already loaded to the Forms Collection, a hidden instance will load. This can lead to unexpected results.
Of course, if the Form referred to is already loaded as a subform, the Form_ reference will not return that subform but instead load a hidden instance completely separate from the subform.
BTW You can check if a Form is loaded by testing its IsLoaded Property via the AllForms Collection.
Code:
CurrentProject.AllForms("formname").IsLoaded
This will return True if the form is an item in the Forms Collection. It will return False if an instance is not loaded or is loaded as a subform.