Ref. to a variable in another form?

B

Bob

Hi,

I woke up this morning to an Access snag! I hope someone
can help!

I have formA which contains subformformB in it. In the
VBA code, behind formA I declare a variable in the top
part of the page called x as bool. This variable gets set
and unset by the private procedures in formA.

But, sometimes I would like to read variable x but from
the VBA code thats behind subformB. How do I reference x
from subFormB when x is declared in code behind FormA.

Thanking you all in advance!

Bob
 
M

Marshall Barton

Bob said:
I have formA which contains subformformB in it. In the
VBA code, behind formA I declare a variable in the top
part of the page called x as bool. This variable gets set
and unset by the private procedures in formA.

But, sometimes I would like to read variable x but from
the VBA code thats behind subformB. How do I reference x
from subFormB when x is declared in code behind FormA.


First, the variable must be declared Public (in the
declaration section of formA's module) so it can be accessed
from outside formA's module.

Since a form's module is a class module, whenever the form
is open, the variable is a property of formA's class so it
can be accessed the same way any property can be referenced.
From a subform in FormA it would just be:

Parent.x

From another form or a standard module, you need to use the
full form reference:

Forms!FormA.x
 

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