|
-
May 3rd, 2006, 09:50 AM
#1
Thread Starter
New Member
Checkbox question
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?
-
May 3rd, 2006, 09:56 AM
#2
Re: Checkbox question
 Originally Posted by mike3847
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"?
Lottery is a tax on people who are bad at maths
If only mosquitoes sucked fat instead of blood...
To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)
-
May 3rd, 2006, 09:58 AM
#3
Addicted Member
Re: Checkbox question
Assuming that you're checkbox's are in a array you can use this.
VB Code:
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.
Are we alive or just breathing?
-
May 3rd, 2006, 09:59 AM
#4
Thread Starter
New Member
Re: Checkbox question
They're just autoshapes. Like I want to use:
ActiveSheet.Shapes("Shape1").Select
but only if CheckBox 1 is checked on the user form.
-
May 3rd, 2006, 10:05 AM
#5
Thread Starter
New Member
Re: Checkbox question
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()
-
May 3rd, 2006, 10:41 AM
#6
-
May 3rd, 2006, 11:19 AM
#7
Re: Checkbox question
 Originally Posted by mike3847
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....
-
May 3rd, 2006, 11:21 AM
#8
Re: Checkbox question
you would end up like
VB Code:
sub test()
Load StateSelect
CheckBox1.Value = Checked
'checked instead of true
StateSelect.Show
end sub()
-
May 3rd, 2006, 11:57 AM
#9
Re: Checkbox question
 Originally Posted by TheBigB
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.... 
Actually, they are either vbChecked of vbUnChecked which represent 0 and 1. Both of these will work
VB Code:
Private 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 Sub
But, I would recommend always using the vb constant as it makes the code much, much easier to understand when reviewing it.
-
May 3rd, 2006, 11:58 AM
#10
Thread Starter
New Member
Re: Checkbox question
doesn't work. Says "Object Required"
-
May 3rd, 2006, 12:03 PM
#11
Re: Checkbox question
 Originally Posted by mike3847
doesn't work. Says "Object Required"
What doesn't work?
Are you using VB6 or VBA?
-
May 3rd, 2006, 12:15 PM
#12
Thread Starter
New Member
Re: Checkbox question
I am using VB6 within Excel 2000.
-
May 3rd, 2006, 12:17 PM
#13
Re: Checkbox question
 Originally Posted by mike3847
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.
-
May 3rd, 2006, 12:19 PM
#14
Thread Starter
New Member
Re: Checkbox question
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.
-
May 3rd, 2006, 04:48 PM
#15
Re: Checkbox question
Incidentally, in VBA the checkbox does not have a Checked property. It has a Value property, which is boolean.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|