Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Subform variable scope question

Status
Not open for further replies.

duanecwilson

Programmer
Jul 15, 2005
26
US
If I declare a module level variable (I think it's called that) on FormA and initialize it on the Load event, will it be visible to the after_update event on a combobox on SubformB or SubformC? I want to set this variable based on whether these fields have changed or not. I have 2 unbound subforms and am updating a table based on whether any of 4 different fields have been updated or not and which one was. This update is going to occur when the main form, FormA is closed.

I know I can use a global variable, but don't want to if I don't have to.



Duane Wilson
 
Your wording in a little confusing so I am not completely sure of what you are asking, but once form A closes the variable declared in form A goes out of scope. Any time prior to that the variable remains in scope and the subforms can reference the variable.

If you want to reference a variable declared in form A from the subforms, the variable must be public in form A. Example in frmA

public myVar as string

To call this variable from the subforms you need to explicitly reference the form class. Example in frmB

form_frmA.myVar = "updated in B"

you can not just reference "myVar
 
Thank you for the reply. It is very clear. I didn't know about referencing a variable in frmA from frmB that way. It turns out I found a different way to solve the problem, but this will be here for next time.

Duane Wilson
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top