Help checking values of controls on userform

Bagharmin

Board Regular
Joined
Nov 22, 2010
Messages
168
I already have a nice little loop that I use to clear all the controls on a userform I created. The main part of the code is below.

Code:
For Each COptions In UserForm1.Controls
     If TypeName(COptions) = "CheckBox" Or TypeName(COptions) = "OptionButton" Or TypeName(COptions) = "TextBox" Then
          COptions.Value = False
     End If
Next

What I'm wanting to do now is come up with a way to store all the values of all the controls in another nice little loop. What I came up with was:

Code:
For Each COptions In UserForm1.Controls
     X = X + 1
     Choice(X) = COptions.Value
Next

VBA doesn't like it. "X" is dim'd as Integer, Choice() as Variant, and COptions as Control and I ReDim'd Choice at the beginning of the code. I want the loop to go through each control on the userform and store it's value, whether it's a T/F value, number, or text. However, I keep getting an "Object doesn't support this property or method" error at the "Choice(X) = COptions.Value" line. Is there a way to do what I'm trying to do?
 
Last edited:

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Actually, I think I found my problem. I forgot that Frames are controls on the userform and they don't have the value property. I modified my code so that it only checked for checkboxes, textboxes, optionbuttons, and spinbuttons. Once I did that, it worked fine. Sorry for the trouble.
 
Upvote 0

Forum statistics

Threads
1,224,587
Messages
6,179,740
Members
452,940
Latest member
Lawrenceiow

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top