ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   OPtion Button (https://www.excelbanter.com/excel-programming/418622-option-button.html)

Art

OPtion Button
 
Hello:

I made a userform with 2 option buttons, however When I reference the option
buttons in another vba module, it does not recognize it? It always diplays it
either as 0 value or false. How can reference the option button in another
code?

Please help.

JLGWhiz

OPtion Button
 
UserForms are not part of a module, they exist at the project level. To
refer to a control on the UserForm, such as an option button, from outside
the UserForm code, you would have to include the UserForm in the reference:

myVar = UserForm1.OptionButton1.Value

"art" wrote:

Hello:

I made a userform with 2 option buttons, however When I reference the option
buttons in another vba module, it does not recognize it? It always diplays it
either as 0 value or false. How can reference the option button in another
code?

Please help.


JLGWhiz

OPtion Button
 
And the UserForm must be active when calling for any control values.

"art" wrote:

Hello:

I made a userform with 2 option buttons, however When I reference the option
buttons in another vba module, it does not recognize it? It always diplays it
either as 0 value or false. How can reference the option button in another
code?

Please help.


Chip Pearson

OPtion Button
 
And the UserForm must be active when calling for any control values.

Nope, not true. For example,

Load UserForm1
UserForm1.TextBox1.Text = "abcd"
Debug.Print UserForm1.TextBox1.Text
Unload UserForm1

As long as the form is still in memory (hidden with Hide but not
dumped with Unload), you can access control values.

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)


On Thu, 16 Oct 2008 14:03:02 -0700, JLGWhiz
wrote:

And the UserForm must be active when calling for any control values.

"art" wrote:

Hello:

I made a userform with 2 option buttons, however When I reference the option
buttons in another vba module, it does not recognize it? It always diplays it
either as 0 value or false. How can reference the option button in another
code?

Please help.


JLGWhiz

OPtion Button
 
You are right Chip, guess I had better mind my semantics. <g

"Chip Pearson" wrote:

And the UserForm must be active when calling for any control values.


Nope, not true. For example,

Load UserForm1
UserForm1.TextBox1.Text = "abcd"
Debug.Print UserForm1.TextBox1.Text
Unload UserForm1

As long as the form is still in memory (hidden with Hide but not
dumped with Unload), you can access control values.

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)


On Thu, 16 Oct 2008 14:03:02 -0700, JLGWhiz
wrote:

And the UserForm must be active when calling for any control values.

"art" wrote:

Hello:

I made a userform with 2 option buttons, however When I reference the option
buttons in another vba module, it does not recognize it? It always diplays it
either as 0 value or false. How can reference the option button in another
code?

Please help.



Art

OPtion Button
 
I don't understand what you are saying.
What I did was just hide the userform instead of unloading it, so the users
selection still stays. Is there another way to do that?

Thanks for responding.




"JLGWhiz" wrote:

UserForms are not part of a module, they exist at the project level. To
refer to a control on the UserForm, such as an option button, from outside
the UserForm code, you would have to include the UserForm in the reference:

myVar = UserForm1.OptionButton1.Value

"art" wrote:

Hello:

I made a userform with 2 option buttons, however When I reference the option
buttons in another vba module, it does not recognize it? It always diplays it
either as 0 value or false. How can reference the option button in another
code?

Please help.


JLGWhiz

OPtion Button
 
The option button has two values, True and False. As Chip Pearson pointed
out, you should be able to access the option button value if the form is
hidden, but not if you unload it. Look up Unload in the VBA help file.
Access VBA help by pressing Alt + F11.

If your UserForm is UserForm1 and your OptionButton is OptionButton1, then
copy and paste the code below into your code module1.

Sub optBtnTest()
Load UserForm1
MsgBox UserForm1.OptionButton1.Value
Unload UserForm1
End Sub

Then run the macro.

You can also set the Control Source in the OptionButton properties to a cell
on a sheet that would show you the value of the OptionButton.

"art" wrote:

I don't understand what you are saying.
What I did was just hide the userform instead of unloading it, so the users
selection still stays. Is there another way to do that?

Thanks for responding.




"JLGWhiz" wrote:

UserForms are not part of a module, they exist at the project level. To
refer to a control on the UserForm, such as an option button, from outside
the UserForm code, you would have to include the UserForm in the reference:

myVar = UserForm1.OptionButton1.Value

"art" wrote:

Hello:

I made a userform with 2 option buttons, however When I reference the option
buttons in another vba module, it does not recognize it? It always diplays it
either as 0 value or false. How can reference the option button in another
code?

Please help.



All times are GMT +1. The time now is 02:14 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com