Userform variable question 
Author Message
 Userform variable question

Hi,

I am having trouble figuring out how to be able to use a
variable created in a userform code in the main macro.

eg.
I want to be able to use the variable ABC generated by
this statement in the userform:-
If OptionButton1.Value = True Then ABC = 6

In the main macro in a later action.

I have tried Dim ABC just before the UserForm.Show
statement and I have tried including it in the userform
code but it never seems to take on the value of 6.

Any hints as to what I am doing wrong please.

Many thanks
Smiffy



Thu, 18 Aug 2005 05:15:18 GMT  
 Userform variable question
Hi Smiffy,

If you wud declare ABC as a public variable, it wud
certainly be carried through.

Dim ABC As Integer
in the general declaration section of a standard module.
If the 'main macro' is residing in a standard module, then
declare the variable in the general declaration section of that module.

Krgrds,
Perry



Quote:
> Hi,

> I am having trouble figuring out how to be able to use a
> variable created in a userform code in the main macro.

> eg.
> I want to be able to use the variable ABC generated by
> this statement in the userform:-
> If OptionButton1.Value = True Then ABC = 6

> In the main macro in a later action.

> I have tried Dim ABC just before the UserForm.Show
> statement and I have tried including it in the userform
> code but it never seems to take on the value of 6.

> Any hints as to what I am doing wrong please.

> Many thanks
> Smiffy



Thu, 18 Aug 2005 08:28:31 GMT  
 Userform variable question
Hi Perry,
thank you for your help again.

Ok, I am a bit slow  (and i do realise that this is basic
stuff)

I have the macro stored in Normal template
The macro shows in vba with (general) in the left hand
pull down window and the macro name in the right pull down
window.
I "Dim" the variable as an integer by typing the statement
into the very top of the screen (sorry about this) with
General in the left window and Declarations in the right.
But the variable still doesnt have a value.
Does the dim statement have to have end sub or anything
after it in the declarations area?

Really sorry to be so basic.

Thanks again

Quote:
>-----Original Message-----
>Hi Smiffy,

>If you wud declare ABC as a public variable, it wud
>certainly be carried through.

>Dim ABC As Integer
>in the general declaration section of a standard module.
>If the 'main macro' is residing in a standard module, then
>declare the variable in the general declaration section
of that module.

>Krgrds,
>Perry



>> Hi,

>> I am having trouble figuring out how to be able to use a
>> variable created in a userform code in the main macro.

>> eg.
>> I want to be able to use the variable ABC generated by
>> this statement in the userform:-
>> If OptionButton1.Value = True Then ABC = 6

>> In the main macro in a later action.

>> I have tried Dim ABC just before the UserForm.Show
>> statement and I have tried including it in the userform
>> code but it never seems to take on the value of 6.

>> Any hints as to what I am doing wrong please.

>> Many thanks
>> Smiffy

>.



Thu, 18 Aug 2005 09:09:16 GMT  
 Userform variable question
Is the macro in a standard module
You can identify standard modules by looking at the Project Explorer window
on the left hand side of VBE.
If the codemodule (where the main macro resides in) is listed under
tree-node: Modules
then it is a standard module.

So, is the main macro listed under a standard module?

P



Quote:
> Hi Perry,
> thank you for your help again.

> Ok, I am a bit slow  (and i do realise that this is basic
> stuff)

> I have the macro stored in Normal template
> The macro shows in vba with (general) in the left hand
> pull down window and the macro name in the right pull down
> window.
> I "Dim" the variable as an integer by typing the statement
> into the very top of the screen (sorry about this) with
> General in the left window and Declarations in the right.
> But the variable still doesnt have a value.
> Does the dim statement have to have end sub or anything
> after it in the declarations area?

> Really sorry to be so basic.

> Thanks again
> >-----Original Message-----
> >Hi Smiffy,

> >If you wud declare ABC as a public variable, it wud
> >certainly be carried through.

> >Dim ABC As Integer
> >in the general declaration section of a standard module.
> >If the 'main macro' is residing in a standard module, then
> >declare the variable in the general declaration section
> of that module.

> >Krgrds,
> >Perry



> >> Hi,

> >> I am having trouble figuring out how to be able to use a
> >> variable created in a userform code in the main macro.

> >> eg.
> >> I want to be able to use the variable ABC generated by
> >> this statement in the userform:-
> >> If OptionButton1.Value = True Then ABC = 6

> >> In the main macro in a later action.

> >> I have tried Dim ABC just before the UserForm.Show
> >> statement and I have tried including it in the userform
> >> code but it never seems to take on the value of 6.

> >> Any hints as to what I am doing wrong please.

> >> Many thanks
> >> Smiffy

> >.



Thu, 18 Aug 2005 09:54:05 GMT  
 Userform variable question
You could store your variable in the Tag property of the form.

Mark Baird

Quote:
> Hi,

> I am having trouble figuring out how to be able to use a
> variable created in a userform code in the main macro.

> eg.
> I want to be able to use the variable ABC generated by
> this statement in the userform:-
> If OptionButton1.Value = True Then ABC = 6

> In the main macro in a later action.

> I have tried Dim ABC just before the UserForm.Show
> statement and I have tried including it in the userform
> code but it never seems to take on the value of 6.

> Any hints as to what I am doing wrong please.

> Many thanks
> Smiffy



Thu, 18 Aug 2005 10:13:24 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. !! userform / variable question !!

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

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

4. Passing a Variable from one Userform to another Userform

5. How do I link a VBA variable to a UserForm text box

6. Pass variable to userform

7. Global variables in userform code

8. VARIABLE value as Userform listbox DEFAULT ?

9. Passing a variable through a UserForm

10. XL97 UserForm entry 2 module variable


 
Powered by phpBB® Forum Software © phpBB Group