Variable not defined

TxStrob

Registered User.
Local time
Today, 13:04
Joined
Sep 23, 2019
Messages
44
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?
 
What is subform container name? I always name container different from object it holds, like ctrEx.

Is subform name Example1?

Syntax behind main form would be like: Me.subformcontainername!txtbox2
 
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.
 
When using the "Form_" syntax from anywhere, you MUST include the entire path starting with the main form.

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.
 

Users who are viewing this thread

Back
Top Bottom