Type mismatch error for checkbox array

H

Harry-Wishes

I have designed a form containing 4 textboxes and 4 checkboxes. I would like
to store the textboxes in one array and store the checkboxes in another
array. I successfully did this with the textboxes but had problems with the
checkboxes. I get a Type mismatch Run-time error '13' when I initialize the
array with assignments using the Set command (see below). The code for
storing items in each array are identical so I am at a lost. Is the
assigmnent for checkboxes different in some way? Help greatly welcome.

Thanks!
Harry-Wishes

Option Base 1

Dim chk(4) As CheckBox

Set chk(1) = Acknowledge_Form1.CheckBox1
Set chk(2) = Acknowledge_Form1.CheckBox2
Set chk(3) = Acknowledge_Form1.CheckBox3
Set chk(4) = Acknowledge_Form1.CheckBox4


Dim aTb(4) As TextBox

Set aTb(1) = Acknowledge_Form1.Box1
Set aTb(2) = Acknowledge_Form1.Box2
Set aTb(3) = Acknowledge_Form1.Box3
Set aTb(4) = Acknowledge_Form1.Box4
 
J

Jean-Guy Marcil

Harry-Wishes was telling us:
Harry-Wishes nous racontait que :
I have designed a form containing 4 textboxes and 4 checkboxes. I
would like to store the textboxes in one array and store the
checkboxes in another array. I successfully did this with the
textboxes but had problems with the checkboxes. I get a Type
mismatch Run-time error '13' when I initialize the array with
assignments using the Set command (see below). The code for storing
items in each array are identical so I am at a lost. Is the
assigmnent for checkboxes different in some way? Help greatly
welcome.

Thanks!
Harry-Wishes

Option Base 1

Dim chk(4) As CheckBox

Set chk(1) = Acknowledge_Form1.CheckBox1
Set chk(2) = Acknowledge_Form1.CheckBox2
Set chk(3) = Acknowledge_Form1.CheckBox3
Set chk(4) = Acknowledge_Form1.CheckBox4


Dim aTb(4) As TextBox

Set aTb(1) = Acknowledge_Form1.Box1
Set aTb(2) = Acknowledge_Form1.Box2
Set aTb(3) = Acknowledge_Form1.Box3
Set aTb(4) = Acknowledge_Form1.Box4

Just change:

Dim chk(4) CheckBox

to

Dim chk(4) As msforms.CheckBox

I guess the compiler is getting confused between Formfields controls
(CheckBox) from the Forms toolbar and Userform controls (which are TextInput
with Formfields and TextBox with Userforms, so no error possible).

It is always better to qualify your variables as precisely as possible.

So, might as well change

Dim aTb(4) As TextBox

to

Dim aTb(4) As msforms.TextBox
 

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