Consulting

Results 1 to 13 of 13

Thread: Looping for check boxes in outlook

  1. #1

    Looping for check boxes in outlook

    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

  2. #2
    try like
    me.controls("checkbox" & i)

  3. #3
    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

  4. #4
    do you have a checkbox0?

  5. #5
    I apologize westconn1. It is typo error, it should be from 1 to 10

  6. #6
    no problem

    if you problem is solved, please mark thread as so

  7. #7
    I apologize westconn1 for late reply.

    I am receiving t
    he error in the same line even after changing it to 1 to 10

    If chx.Value = True Then

    Please help.

    Thanks
    Praveen

  8. #8
    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

  9. #9
    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

  10. #10
    chx has no value property as it is only a boolean variable
    this also means it has no caption property or an other property, nothing can be . after chx

  11. #11
    My main requirement here is to get the caption of the checkbox. Could you please tell what I add to get the caption?

    Thanks

  12. #12
    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

  13. #13
    It worked perfectly as I wanted. Thanks a lot westconn1!

    I am closing this thread.

    Thanks
    Praveen
    Last edited by praveenpatel; 08-12-2014 at 10:26 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •