PDA

Click to See Complete Forum and Search --> : Checkbox question


mike3847
May 3rd, 2006, 09:50 AM
I have 20 checkboxes, and 20 objects. I want to load the user form with the checkboxes, and for each checkbox selected, I want to select that object. So CheckBox1 corresponds to Object1 and so forth to 20. Any ideas?

krtxmrtz
May 3rd, 2006, 09:56 AM
I have 20 checkboxes, and 20 objects. I want to load the user form with the checkboxes, and for each checkbox selected, I want to select that object. So CheckBox1 corresponds to Object1 and so forth to 20. Any ideas?
What kind of objects? And what do you exactly mean by "select that object"?

Piller
May 3rd, 2006, 09:58 AM
Assuming that you're checkbox's are in a array you can use this.

Private Sub Check1_Click(Index As Integer)
If Check1(Index).Value = vbChecked Then
'Code here
End If
End Sub

Checks to see if the check box is Checked, then runs the code you want it to.

mike3847
May 3rd, 2006, 09:59 AM
They're just autoshapes. Like I want to use:

ActiveSheet.Shapes("Shape1").Select

but only if CheckBox 1 is checked on the user form.

mike3847
May 3rd, 2006, 10:05 AM
I tryed the above code, but cannot get it to work. I can't even figure out how to get the value of the checkbox (1, true, 0, or false). Why is this wrong?

sub test()
Load StateSelect
CheckBox1.Value = True
StateSelect.Show
end sub()

Hack
May 3rd, 2006, 10:41 AM
Is this Excel VBA?

TheBigB
May 3rd, 2006, 11:19 AM
I tryed the above code, but cannot get it to work. I can't even figure out how to get the value of the checkbox (1, true, 0, or false). Why is this wrong?

sub test()
Load StateSelect
CheckBox1.Value = True
StateSelect.Show
end sub()

Values of checkboxes are expressed as 'checked' or 'unchecked' which I think represent 0 or 1...
Why it isn't a boolean like an option box, I dunno.... I guess some weird microsoft thing.... :confused:

TheBigB
May 3rd, 2006, 11:21 AM
you would end up like

sub test()
Load StateSelect
CheckBox1.Value = Checked
'checked instead of true
StateSelect.Show
end sub()

Hack
May 3rd, 2006, 11:57 AM
Values of checkboxes are expressed as 'checked' or 'unchecked' which I think represent 0 or 1...
Why it isn't a boolean like an option box, I dunno.... I guess some weird microsoft thing.... :confused:Actually, they are either vbChecked of vbUnChecked which represent 0 and 1. Both of these will workPrivate Sub Command1_Click()
If Check1.Value = 0 Then
MsgBox "No"
Else
MsgBox "Yes"
End If
End Sub

Private Sub Command1_Click()
If Check1.Value = vbUnChecked Then
MsgBox "No"
Else
MsgBox "Yes"
End If
End SubBut, I would recommend always using the vb constant as it makes the code much, much easier to understand when reviewing it.

mike3847
May 3rd, 2006, 11:58 AM
doesn't work. Says "Object Required"

Hack
May 3rd, 2006, 12:03 PM
doesn't work. Says "Object Required"What doesn't work?

Are you using VB6 or VBA?

mike3847
May 3rd, 2006, 12:15 PM
I am using VB6 within Excel 2000.

Hack
May 3rd, 2006, 12:17 PM
I am using VB6 within Excel 2000.VB6 is not within anything. It is a completely stand-along development platform that is totally outside of any Office product. That is why my code didn't work. You really aren't using VB6. You are using Excel VBA, and there are many, many features of VB that VBA does not support.

I'm moving your VBA question to Office Development.

mike3847
May 3rd, 2006, 12:19 PM
I was just going off what my Visual Basic says, and that is 6.0. It is within excel. I wasn't aware that it was referred to as VBA.

zaza
May 3rd, 2006, 04:48 PM
Incidentally, in VBA the checkbox does not have a Checked property. It has a Value property, which is boolean.