Go Back   Access World Forums > Microsoft Access Discussion > Modules & VBA

 
Reply
 
Thread Tools Rate Thread Display Modes
Old 11-08-2019, 07:58 PM   #1
TxStrob
Newly Registered User
 
Join Date: Sep 2019
Posts: 44
Thanks: 0
Thanked 0 Times in 0 Posts
TxStrob is on a distinguished road
Variable not defined

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?

TxStrob is offline   Reply With Quote
Old 11-08-2019, 08:08 PM   #2
June7
AWF VIP
 
June7's Avatar
 
Join Date: Mar 2014
Location: The Great Land
Posts: 2,403
Thanks: 0
Thanked 559 Times in 555 Posts
June7 will become famous soon enough June7 will become famous soon enough
Re: Variable not defined

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
__________________
Attach File Manager is below Advanced editor window, click Go Advanced below Quick Reply window. To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.
DEBUG! DEBUG! DEBUG!
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
June7 is offline   Reply With Quote
Old 11-08-2019, 09:34 PM   #3
Pat Hartman
Super Moderator
 
Join Date: Feb 2002
Location: Stratford,Ct USA
Posts: 28,249
Thanks: 15
Thanked 1,592 Times in 1,512 Posts
Pat Hartman is a name known to all Pat Hartman is a name known to all Pat Hartman is a name known to all Pat Hartman is a name known to all Pat Hartman is a name known to all Pat Hartman is a name known to all
Re: Variable not defined

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.

__________________
Bridge Players Still Know All the Tricks
Pat Hartman is offline   Reply With Quote
Old 11-08-2019, 10:25 PM   #4
theDBguy
Iím here to help
 
theDBguy's Avatar
 
Join Date: Oct 2018
Location: SunnySandyEggo
Posts: 5,721
Thanks: 57
Thanked 1,260 Times in 1,241 Posts
theDBguy has a spectacular aura about theDBguy has a spectacular aura about
Re: Variable not defined

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.
__________________
Just my 2 cents...

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
theDBguy is online now   Reply With Quote
Old 11-09-2019, 12:50 AM   #5
Galaxiom
Super Moderator
 
Join Date: Jan 2009
Location: NSW Australia
Posts: 11,651
Thanks: 98
Thanked 1,499 Times in 1,414 Posts
Galaxiom is a splendid one to behold Galaxiom is a splendid one to behold Galaxiom is a splendid one to behold Galaxiom is a splendid one to behold Galaxiom is a splendid one to behold Galaxiom is a splendid one to behold Galaxiom is a splendid one to behold
Re: Variable not defined

Quote:
Originally Posted by Pat Hartman View Post
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.

Galaxiom is offline   Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Variable not defined irade92 Modules & VBA 4 11-19-2017 09:38 AM
Object variable or With block variable not defined PorscheMan Modules & VBA 3 01-16-2013 12:33 AM
variable not defined... mfuada Modules & VBA 4 02-19-2009 02:05 AM
User-Defined Variable Not Defined mtairhead Modules & VBA 11 12-21-2006 06:16 AM
Variable not defined? T588 Modules & VBA 2 04-29-2003 10:40 AM




All times are GMT -8. The time now is 08:04 AM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Featured Forum post


Sponsored Links


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World