Passing a Variable from one Userform to another Userform 
Author Message
 Passing a Variable from one Userform to another Userform

Hi, I'm trying to pass a variable from DATEFORM to ALARMFORM, the variable
name is "AlarmValue".  My code below does not work.
NUM is an integer passed by one of 48 buttons on the DATEFORM, this works
great as the debug.print statement proves it does pass the variable
correctly.
The problem is I pass this statement "AlarmValue = NUM"  AlarmValue should
retain it's value of "56" when ALARMFORM is loaded but doesn't.  Does anyone
know a sure fire way to pass a variable from one form to another?  Do I have
to use a Range to store the data in?

'This code is in the DATEFORM code module.

Public AlarmValue As Integer

Sub AlarmButtonClick(NUM As Integer)
AlarmValue = NUM
Debug.Print AlarmValue
Load AlarmForm
AlarmForm.Show
End Sub



Fri, 11 Feb 2005 14:23:17 GMT  
 Passing a Variable from one Userform to another Userform


Quote:
> Hi, I'm trying to pass a variable from DATEFORM to ALARMFORM, the
> variable name is "AlarmValue".  My code below does not work.
> NUM is an integer passed by one of 48 buttons on the DATEFORM, this
> works great as the debug.print statement proves it does pass the
> variable correctly.
> The problem is I pass this statement "AlarmValue = NUM"  AlarmValue
> should retain it's value of "56" when ALARMFORM is loaded but doesn't.
>  Does anyone know a sure fire way to pass a variable from one form to
> another?  Do I have to use a Range to store the data in?

> 'This code is in the DATEFORM code module.

> Public AlarmValue As Integer

> Sub AlarmButtonClick(NUM As Integer)
> AlarmValue = NUM
> Debug.Print AlarmValue
> Load AlarmForm
> AlarmForm.Show
> End Sub

1. It's a very bad idea to put the code above in the DATEFORM code module
it really should go in a standard module.  If you had done that then the
code above would work.

The biggest reason for doing this is simply that the minute you unload
DATEFORM the public value is no longer available.  Kind of defeats the
object of the exercise.

2. If you insist on doing it that way then where ever you have the
variable AlarmValue in the ALARMFORM it must be fully qualified.

        DATEFORM.AlarmValue

as I said, if AlarmValue is in a standard module it is not necessary to
do that.

--
Pengbo

When being chased by a hungry dragon, you only have to out run the
slowest person in the group... not the dragon.

        - Unknown



Fri, 11 Feb 2005 15:40:52 GMT  
 Passing a Variable from one Userform to another Userform
Try placing the "Public AlarmValue As Integer" statement in a regular module
instead of inside the userform.
______________________
Robert Rosenberg
R-COR Consulting Services
Microsoft MVP - Excel

Quote:
> Hi, I'm trying to pass a variable from DATEFORM to ALARMFORM, the variable
> name is "AlarmValue".  My code below does not work.
> NUM is an integer passed by one of 48 buttons on the DATEFORM, this works
> great as the debug.print statement proves it does pass the variable
> correctly.
> The problem is I pass this statement "AlarmValue = NUM"  AlarmValue should
> retain it's value of "56" when ALARMFORM is loaded but doesn't.  Does
anyone
> know a sure fire way to pass a variable from one form to another?  Do I
have
> to use a Range to store the data in?

> 'This code is in the DATEFORM code module.

> Public AlarmValue As Integer

> Sub AlarmButtonClick(NUM As Integer)
> AlarmValue = NUM
> Debug.Print AlarmValue
> Load AlarmForm
> AlarmForm.Show
> End Sub



Fri, 11 Feb 2005 15:42:18 GMT  
 Passing a Variable from one Userform to another Userform
Thanks guys!

Regards, Rocky McKinley


Quote:
> Try placing the "Public AlarmValue As Integer" statement in a regular
module
> instead of inside the userform.
> ______________________
> Robert Rosenberg
> R-COR Consulting Services
> Microsoft MVP - Excel


> > Hi, I'm trying to pass a variable from DATEFORM to ALARMFORM, the
variable
> > name is "AlarmValue".  My code below does not work.
> > NUM is an integer passed by one of 48 buttons on the DATEFORM, this
works
> > great as the debug.print statement proves it does pass the variable
> > correctly.
> > The problem is I pass this statement "AlarmValue = NUM"  AlarmValue
should
> > retain it's value of "56" when ALARMFORM is loaded but doesn't.  Does
> anyone
> > know a sure fire way to pass a variable from one form to another?  Do I
> have
> > to use a Range to store the data in?

> > 'This code is in the DATEFORM code module.

> > Public AlarmValue As Integer

> > Sub AlarmButtonClick(NUM As Integer)
> > AlarmValue = NUM
> > Debug.Print AlarmValue
> > Load AlarmForm
> > AlarmForm.Show
> > End Sub



Fri, 11 Feb 2005 17:59:17 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Variable(s) Reset by Showing 2nd UserForm on top 1st UserForm

2. Two Questions - Making a userform active / Accessing a userform via a variable

3. Pass variable to userform

4. Passing a variable through a UserForm

5. Passing variables between userforms and/or normal procedures

6. Excel 97: Pass variable from userform to Sub ?

7. Passing variables or arrays to userforms

8. Passing variables or arrays to userform objects

9. Passing UserForm Variable To Class Module

10. Passing Variables between UserForm/Module


 
Powered by phpBB® Forum Software © phpBB Group