View Full Version : [SOLVED:] Looping for check boxes in outlook
praveenpatel
08-07-2014, 09:48 PM
Hi all,
This is my first post in this forum. Please apologize whatever I am posting doesn't make sense.
I have learnt VBA self and my knowledge on VBA is basic.
I was trying to loop checkboxes in the userform but didn't understood how to do that. I have 10 checkboxes named checkbox1, checkbox2, checkbox3,............checkbox10. I was trying to loop these checkboxes something like:
for i = 0 to 10
if checkbox(i).value=true then
msgbox checkbox(i).caption & " is checked"
else
msgbox checkbox(i).caption & " is not checked"
endif
next
but was not able to find the right way for doing this. Can somebody help me on this?
I tried searching for one but couldn't find the right one.
Thanks in advance :):):)
Praveen
westconn1
08-08-2014, 03:42 AM
try like
me.controls("checkbox" & i)
praveenpatel
08-08-2014, 04:38 AM
Thanks for the reply westconn1
I tried this
Private Sub CommandButton2_Click()
Dim i As Integer
Dim chx As Boolean
For i = 0 To 10
chx = Me.Controls("CheckBox" & i)
If chx.Value = True Then
MsgBox " " & chx.Caption
Else
MsgBox " and " & chx.Caption
End If
Next
End Sub
I received an error
"Compile error:
Invalid qualifier"
Please let me know if I am doing anything wrong
Thanks
Praveen
westconn1
08-08-2014, 05:44 AM
do you have a checkbox0?
praveenpatel
08-08-2014, 09:01 PM
I apologize westconn1. It is typo error, it should be from 1 to 10
westconn1
08-09-2014, 12:08 AM
no problem
if you problem is solved, please mark thread as so
praveenpatel
08-11-2014, 10:55 PM
I apologize westconn1 for late reply.
I am receiving the error in the same line even after changing it to 1 to 10
If chx.Value = True Then
Please help.
Thanks
Praveen
westconn1
08-12-2014, 02:47 AM
chx has no value property as it is only a boolean variable
try like
if chx then
which is the same as
if chx = true then
in either case the chx variable is unnecessary
as you can use like
if me.controls("CheckBox" & i) then
praveenpatel
08-12-2014, 03:31 AM
Now I am receiving error in the line
MsgBox " and " & chx.Caption
I need message box to show the caption of the checkbox. Please can you tell me how to get that?
Thanks
Praveen
westconn1
08-12-2014, 04:06 AM
chx has no value property as it is only a boolean variablethis also means it has no caption property or an other property, nothing can be . after chx
praveenpatel
08-12-2014, 04:43 AM
My main requirement here is to get the caption of the checkbox. Could you please tell what I add to get the caption?
Thanks
westconn1
08-12-2014, 02:25 PM
msgbox me.controls("CheckBox" & 1).caption
if for some reason you really need a variable to represent the checkbox, it would have to be an object type, it could be a specific type, like control or checkbox, or a generic type object or a variant that can contain an object
and you would need to use the Set keyword
set objchx = me.controls(Checkbox" & i)
objchx would in this case have all the properties and methods of a checkbox
praveenpatel
08-12-2014, 08:28 PM
It worked perfectly as I wanted. Thanks a lot westconn1!
I am closing this thread.
Thanks
Praveen
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.