Subform opens before main form

J

JimP

Can I pass a value from the main form before the subform opens?

Can I have a public variable on the main form that passes a value to the
sub-form when it opens?
 
M

Marshall Barton

JimP said:
Can I pass a value from the main form before the subform opens?

Can I have a public variable on the main form that passes a value to the
sub-form when it opens?


No.

The usual way to do something like that is for the subform
to pull the value from the main form in the subform's Open
or Load event. Use the Load event is you want are assigning
variable to a control's Value.

Since the main form variable is public, the code would
simply be:

xx = Parent.variable
 
J

JimP

How do I refer to the main form, given that the sub-form could be in various
main forms?

i.e. How do I know what the main form name is?
 
M

Marshall Barton

You don't need the name of the main form. That's why you
use the Parent property.

Just in case you have some strange reason for getting the
name of the main form it's Parent.Name
 
J

JimP

Thank you - I didn't realize "Parent" was literal.

On the same issue, is it possible to use variables on the main form and pass
the values to the sub-forms? Would this simply be declaring them public on
the main form?

The use of sub-forms is new to me and I apologize for the long thread.

Jim

Marshall Barton said:
You don't need the name of the main form. That's why you
use the Parent property.

Just in case you have some strange reason for getting the
name of the main form it's Parent.Name
--
Marsh
MVP [MS Access]

How do I refer to the main form, given that the sub-form could be in
various
main forms?

i.e. How do I know what the main form name is?


"Marshall Barton" wrote
 
M

Marshall Barton

That's the same question we've been discussing. Because the
main form is initialized before any subforms, you can not
reliably "pass" values (of any kind) to a subform until all
the subforms have been initialized. That's why I keep
saying that the subform's should "pull" the values from the
mainform.

The important point here is that Public **variables** in a
form module are properties of the form object and can be
referenced as I indicated earlier.

If you are using the word "variable" only loosely and mean
something other than a VBA variable in a module, then try to
explain more about what you are really trying to accomplish.
 
J

JimP

I think I get it - thanks for your help.


Marshall Barton said:
That's the same question we've been discussing. Because the
main form is initialized before any subforms, you can not
reliably "pass" values (of any kind) to a subform until all
the subforms have been initialized. That's why I keep
saying that the subform's should "pull" the values from the
mainform.

The important point here is that Public **variables** in a
form module are properties of the form object and can be
referenced as I indicated earlier.

If you are using the word "variable" only loosely and mean
something other than a VBA variable in a module, then try to
explain more about what you are really trying to accomplish.
--
Marsh
MVP [MS Access]

On the same issue, is it possible to use variables on the main form and
pass
the values to the sub-forms? Would this simply be declaring them public on
the main form?

"Marshall Barton" wrote
 
J

JimP

"xx = Parent.variable" is giving me a "Application-defined or object defined
error" Any suggestions?
 
M

Marshall Barton

JimP said:
"xx = Parent.variable" is giving me a "Application-defined or object defined
error" Any suggestions?


What are you using for "xx"? How is it declared in the
subform?

How did you declare "variable" in the main form?

If you would post the actual names of the forms, objects and
variables you are using, we could avoid all the ambiguity
caused by generalized names.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top