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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

scope of variables across nested forms

Status
Not open for further replies.

Bastien

Programmer
May 29, 2000
1,683
CA
I have a form with 2 nested subforms in it. If create a variable in the main form, can the others see it? Or if I create a variable in one of the subforms, can the other forms see it?

TIA Bastien

There are many ways to skin this cat,
but it still tastes like chicken
 
If you declare a variable as public in a form, it becomes a public property of that form. So if you create a variable in you main form:

Code:
public strWhatever as string

You can call it through

Code:
parent.strWhatever

from your subform and the other way around. Note that autocomplete does not work in code, but the variable does exists.

Best regards and please be nice to cats. ;-)
 
Any control on any loaded form or subform is accessible givien the correct reference syntax.

There are many ways to refer to a control on a form or subform.

Try checking the VB help under subforms.

This gives plenty of examples

Tom
 
thanks Bastien

There are many ways to skin this cat,
but it still tastes like chicken
 
from the help i got the notation as seen below when referencing a control on a sub form from the main form...

here i am trying to set a value for a field 'itemsdiscussed'

this code is in the onCurrent module of the main (minmain ) form and while it seems to execute when i step thorugh the code, it does not update the field.

If ((Forms!MinMain!meeting2.ItemsDiscussed.Value = "") Or IsNull(Forms!MinMain!meeting2.ItemsDiscussed.Value)) Then
items = 1
Forms!MinMain!meeting2.ItemsDiscussed.Value = Forms!MinMain!meeting1.MeetingNo.Value & "-" & items
End If

any ideas? Bastien

There are many ways to skin this cat,
but it still tastes like chicken
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top