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

Passing a reference to a subform

Status
Not open for further replies.

astraltango

Programmer
Joined
Nov 19, 2003
Messages
18
Location
AU
I have a parent form that has a subform (subForm1) that opens a form (form1)

form1 then needs to reference subForm1

form1 is opened by multiple forms, so I can't hardcode the reference to subform1 in form1

I want to declare a public variable (callingFormVariable) in form1 (or as a global), that I then update with a reference to subform1 when subForm1 opens form1

I understand that I can't reference subform1 if I set callingFormVarible to the subform's name, ie:
callingFormVarible=Me.Name
as I need to reference subform1 through it's parent

if I have another public variable callingFormParentVariable, which I set to the name of the subform's parent form, I still can't reference subForm1 since I need the name of the subform control on the parent form

is there any way I can reference the name of this subform control from within subForm1, and what would the syntax be to reference this from Form1?

alternatively, is there an easier way to reference subForm1 through a direct reference variable? ie, instead of using the string name of the subform, can I declare callingFormVariable AS Form and set it as a reference to subForm1? if so, what would the syntax be to update callingFormVariable and what would the syntax be to use it to reference subForm1 from form1?

I hope I haven't confused you as much as I have myself :D
 
Go with the easier way. Make your variable (which must be Public in a standard module) of type Form. Within the subform code, set the variable to Me. (If the code to set it is in the main form, set it to Me.subformcontrol.Form)

Set callingFormVariable = Me
or Set callingFormVariable = Me.subform1.Form

Rick Sprague
Want the best answers? See faq181-2886
To write a program from scratch, first create the universe. - Paraphrased from Albert Einstein
 
if I declare the public variable in a standard module I get the error:
"compile error. invalid use of property"

if I declare the public variable in form1, I get the following error when the variable is updated:
"run-time error '91':
Object variable or With block variable not set"
 
You're saying that you put
Public callingFormVariable As Form
in the Declarations section of a standard module and it gave you "Invalid use of property"?

Naw. No way it would do that.

It might go the other way around, though. If you put the declaration in a Form module, it automatically becomes a property of the form, so I can see that error message resulting. If you put it in a standard module and failed to set it, you would get "Object variable or With block variable not set" when you tried to reference it. Go back and check it again.

Rick Sprague
Want the best answers? See faq181-2886
To write a program from scratch, first create the universe. - Paraphrased from Albert Einstein
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top