setting ctl to array of checkboxes yields type mismatch error.

T

Tritan

Dim ChkBoxes() As CheckBox
Dim Ctl As Control
Dim j As Integer
j = 0
For Each Ctl In Me.Controls
If TypeName(Ctl) = "CheckBox" Then
j = j + 1
ReDim Preserve ChkBoxes(1 To j)
error-> Set ChkBoxes(j) = Ctl
End If
Next Ctl

have several checkboxes on a user form that I would like
to manipulate in a for loop. (setting various ranges
differently based on the which checkbox is checked)

When I step thru it Ctl is 'true'. I want to add a
CheckBox to my array not a true. What am I doing wrong.

Any help would be appreciated.
Thanks,
Tritan
 
T

Trevor Shuttleworth

Tritan

Dim ChkBoxes() As Variant

This sets each entry in the array to True or False. Is that what you want ?

Regards

Trevor
 
R

Rob Bovey

Hi Tritan,

Try declaring your array variable as MSForms.Checkbox instead of just
CheckBox, e.g.:

Dim ChkBoxes() As MSForms.CheckBox

--
Rob Bovey, MCSE, MCSD, Excel MVP
Application Professionals
http://www.appspro.com/

* Please post all replies to this newsgroup *
* I delete all unsolicited e-mail responses *
 
T

Tritan

No, I actually want to create an array of checkbox objects
that I can then loop thru and THEN check to see if they
are true or false (checked or unchecked).
I need the objects as CHECKBOX objects.

Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top