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!

passing variables form to subform

Status
Not open for further replies.

JKDeveloper0718

Programmer
Aug 11, 2006
23
US
I have a variable within the vba background in the form_open subroutine that I would like to pass from the main form (frmApplication) to a subform (sfrmFamilyMemebers) that is located on this main form.
the variable is an integer called lappid that needs to be passed to the subform and used as filter for a where clause within the sql string for a openrecordset command. When I try to access the variable in the subform within the form_current routine it gives me a null or at first 0 value then the proper value when more than one record is in the subform. If I try to access the variable from the form_open subroutine within the subform it will produce a zero. I have tried everything possible but it seems that the form_current is the only way to access the variable

any suggestions to why I get a 0 value for a variable passed from the main form to the subform. Also if you do a debug print it will show

0
213

the value I need is the 213 but it gves me 0 if I try accessing this from the form_Current routine

There has to be a way to pass there variables easier.

from the main form I call this in the form open to a variable in the subform

num = 12
Form_sfrmFamilyMembers.num = num

I can change this to a text box and it will pass but if I try to use it anywhere in the subform it will be zero.

 
This has to do with the timing of "Current" event of the subform.

You may try adding an invisible textbox in the main form and assigning the ID to the textbox.

Seaport
 
Well what exactly are you refering to the variable is actually an invisible text box but its also an integer variable.

Dim num as Integer
num = 1233

Or ApplicationID (is the invisible field that is populated by a table) in the main form so when I pass this variable to the subform which is in datasheet view I can see it when I populate a textbox but the subform is being filtered using linked child and master fields (ApplicationId).

I would like to call some vba functions to open an entirely different record set with the ApplicationID variable from the main form. In turn it needs to happen within this subform. But for some reason the variable is not staying within the subform its giving me a zero value.
 
Just wondering if anyone has ever passed variables to a subform from a main form and then been about to manipulate in the form_current subroutine without losing the variable values. Any suggestions at all for this.
 
Any variable declared as Public in a Form Class Module may be used as a property of this form:
Forms![name of mainform].VariableName

or, in a subform:
Me.Parent.Form.VariableName

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top