Check boxes - Access 2002 (1 Viewer)

dcobau

Registered User.
Local time
Tomorrow, 00:11
Joined
Mar 1, 2004
Messages
124
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
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 07:11
Joined
Aug 30, 2003
Messages
36,140
This seems to do what you want:
Code:
Private Sub CheckBoxTest(ctl As String)
  Select Case ctl
    Case "check0"
      MsgBox "First one"
    Case "check2"
      MsgBox "second"
    Case "check4"
      MsgBox "third"
    Case "check6"
      MsgBox "fourth"
  End Select
End Sub

Private Sub Check0_AfterUpdate()
  CheckBoxTest (Me.ActiveControl.Name)
End Sub
 

dcobau

Registered User.
Local time
Tomorrow, 00:11
Joined
Mar 1, 2004
Messages
124
thanks Paul,

it works well for the first check box and nothing happens with the next.

Dave
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 07:11
Joined
Aug 30, 2003
Messages
36,140
Did you change the names to match yours, and of course add code to each checkbox's after update event?
 

dcobau

Registered User.
Local time
Tomorrow, 00:11
Joined
Mar 1, 2004
Messages
124
yes I did Paul, it wouldn't work with the first checkbox otherwise

Dave
 

dcobau

Registered User.
Local time
Tomorrow, 00:11
Joined
Mar 1, 2004
Messages
124
I beg you pardon Paul, your code does work. I mispelled the next check box name.

thanks

Dave
 

Users who are viewing this thread

Top Bottom