Variable not defined (1 Viewer)

TxStrob

Registered User.
Local time
Today, 07:31
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?
 

June7

AWF VIP
Local time
Today, 06:31
Joined
Mar 9, 2014
Messages
5,425
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
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 10:31
Joined
Feb 19, 2002
Messages
42,984
When using the "Form_" syntax from anywhere, you MUST include the entire path starting with the main form.

When you are in the "parent" form for the subform, you should use the Me.mysubform.Form!controlname syntax.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 07:31
Joined
Oct 29, 2018
Messages
21,358
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.
 

Galaxiom

Super Moderator
Staff member
Local time
Tomorrow, 01:31
Joined
Jan 20, 2009
Messages
12,849
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

Top Bottom