VBA question re variables

G

Guest

Hello All

I wonder if someone can help me with this.

I have a form a tab control and 12 pages. On each page a separate piece of
data is captured and at the end this is populated into my table. Users move
to the next page in the sequence by clicking command buttons on each page
which I am trying to code now.

The part I am struggling with is this...

How can I set the value of a variable in one subroutine and use the variable
in another routine without the value of the variable changing which it seems
to do?

Many thanks in advance and kind regards, Nick
 
C

Carl Rapson

Nick said:
Hello All

I wonder if someone can help me with this.

I have a form a tab control and 12 pages. On each page a separate piece of
data is captured and at the end this is populated into my table. Users
move
to the next page in the sequence by clicking command buttons on each page
which I am trying to code now.

The part I am struggling with is this...

How can I set the value of a variable in one subroutine and use the
variable
in another routine without the value of the variable changing which it
seems
to do?

Many thanks in advance and kind regards, Nick

The easiest way to do this is to declare the variable at the module-level.
At the top of your form's code module, after any OPTION statements but
before the first Sub/Function declaration, put something like:

Dim myVariable As Type

The variable will be visible in all routines in the module. If the value
changes, it will be because something in one of your routines changed it.
You could put a Watch on the variable in Debug mode and see where it
changes.

Carl Rapson
 
G

Guest

cheers for this

Carl Rapson said:
The easiest way to do this is to declare the variable at the module-level.
At the top of your form's code module, after any OPTION statements but
before the first Sub/Function declaration, put something like:

Dim myVariable As Type

The variable will be visible in all routines in the module. If the value
changes, it will be because something in one of your routines changed it.
You could put a Watch on the variable in Debug mode and see where it
changes.

Carl Rapson
 

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