Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check box - small doubt

Status
Not open for further replies.

shanmugham

Programmer
Jun 19, 2001
71
0
0
IN
i have chk1 to chk23 check boxes (23 boxes)

i want to clear all check box value as False

the following logic gives error

dim temp as string
For i = 1 To 23
temp = "chk" + CStr(i)
temp.Value = False
Next i

thanks in advance

shan
 
I notice that you haven't as yet marked any of the answers to your questions as helpful/valuable. If you are not getting the right answers, read faq222-2244 to see how to get better answers. If you have found answers to be valuable, read faq 222-2244, especially para 15 to see how to acknowledge them.

For your current question:

The easiest way is to loop through the controls collection, check if you have a CheckBox, then set it to Unchecked:

Dim c As Control
For Each c In Me.Controls
If TypeOf c Is CheckBox Then
c.Value = vbUnchecked
End If
Next

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'
 
Another option would be to use a checkbox array (if that works for your situation). Then you can use the checkbox object directly, i.e. chk(i).value = false. BTW, only objects or controls can use the "." operator. It means you are accessing a property or method.
 
For checkboxes (which have 3 possible vales) I would recommend using the intrinsic VB constants, rather than using the False = 0 identity.

The checkbox constants are:
[tt]
vbUnchecked = 0
vbChecked = 1
vbGrayed = 2
[/tt]

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'
 

<picky and pendant>

.Value = True wouldn't work anyways as True has a value of -1 (Unless you first convert it to a positive).

And, Enums are constants which use a dot "." as well.
Types use them also.

 
LostInCode,
Thx for the additions. It b 2 late to think of everything! :)

I think we're all Bozoes on this bus!
 
However, I do use True and False when setting checkbox values from a db table's "boolean" field, and back, when the check box only can have one of the two states (using Abs() and CBool())

lol. What are "Bozoes"? Or was that meant as "Bozos".

 
>> lol. What are "Bozoes"? Or was that meant as "Bozos".

kinda like spelling potatos as potatoes - d'oh! spelling error has been corrected. btw, the reference is to a firesign theatre comeday album from long, long ago...

"I think we're all Bozos on this bus!
 
Oh, I thought you meant something like Bozo the [clown] from the early sixties which some kids watched.
 
That's probably where it started from... :)

"I think we're all Bozos on this bus!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top