VBA question re variables

  • Thread starter Thread starter Guest
  • Start date Start date
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
 
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
 
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
 
Back
Top