Hi,
I have a form with 14 checkboxes on it. Currently I have a lot of If...Then...Else code behind each AfterUpdate event of the check boxes to perform appropriate action. I would like to centralise this code in the form module and use Select cases to do the same. So far I have this code which, at this stage, should only display a message that tells me the name of the check box I check/uncheck. The code does not work properly; it loops right through all the check boxes in the form (which is correct) displaying a message for each checkbox and telling me its name (which is not what I want - I only want the name of the check box I flagged).
Public Sub CheckOutCheckBoxes()
Dim ckbox As Control
For Each ckbox In Me.Controls ' loop thru all controls
If ckbox.ControlType = acCheckBox Then ' picking out only the checkboxes
Select Case ckbox.Name
Case "InterestedOnly"
If ckbox.Value = True Then ' and only doing stuff if they are set
MsgBox "This is the Interested check box" ' do lots of fun stuff based on this checkbox being true
End If
Case "Participants"
If ckbox.Value = True Then ' and only doing stuff if they are set
MsgBox "This is the Participants check box" ' do lots of fun stuff based on this checkbox being true
End If
' Case "IntendingSubmission"
' If ckbox.Value = True Then ' and only doing stuff if they are set
' do lots of fun stuff based on this checkbox being true
' End If
Case Else
MsgBox "Name is: " & ckbox.Name, , "Unknown checkbox ticked"
End Select
End If
Next
End Sub
Can anybody help?
thanks
Dave
I have a form with 14 checkboxes on it. Currently I have a lot of If...Then...Else code behind each AfterUpdate event of the check boxes to perform appropriate action. I would like to centralise this code in the form module and use Select cases to do the same. So far I have this code which, at this stage, should only display a message that tells me the name of the check box I check/uncheck. The code does not work properly; it loops right through all the check boxes in the form (which is correct) displaying a message for each checkbox and telling me its name (which is not what I want - I only want the name of the check box I flagged).
Public Sub CheckOutCheckBoxes()
Dim ckbox As Control
For Each ckbox In Me.Controls ' loop thru all controls
If ckbox.ControlType = acCheckBox Then ' picking out only the checkboxes
Select Case ckbox.Name
Case "InterestedOnly"
If ckbox.Value = True Then ' and only doing stuff if they are set
MsgBox "This is the Interested check box" ' do lots of fun stuff based on this checkbox being true
End If
Case "Participants"
If ckbox.Value = True Then ' and only doing stuff if they are set
MsgBox "This is the Participants check box" ' do lots of fun stuff based on this checkbox being true
End If
' Case "IntendingSubmission"
' If ckbox.Value = True Then ' and only doing stuff if they are set
' do lots of fun stuff based on this checkbox being true
' End If
Case Else
MsgBox "Name is: " & ckbox.Name, , "Unknown checkbox ticked"
End Select
End If
Next
End Sub
Can anybody help?
thanks
Dave