Check boxes

teel73

Registered User.
Local time
Today, 03:35
Joined
Jun 26, 2007
Messages
205
I have 5 check boxes. I want to be able to display which checkbox is checked. How can I do that in VBA? For example:

If checkbox1 and checkbox4 is checked, I want a message box to display the names of "checkbox1 and checkbox4".
 
Add a function to your form, see below: -

' -------------------------------------------------------------------------
Private Function CheckBoxCheck()
Dim tmpmsg As String

tmpmsg = ""

If Check01.Value = -1 Then
tmpmsg = tmpmsg & "Check Box1" & vbCrLf
End If

If Check02.Value = -1 Then
tmpmsg = tmpmsg & "Check Box2" & vbCrLf
End If

If Check03.Value = -1 Then
tmpmsg = tmpmsg & "Check Box3" & vbCrLf
End If

If Check04.Value = -1 Then
tmpmsg = tmpmsg & "Check Box4" & vbCrLf
End If

If tmpmsg <> "" Then
MsgBox "You have checked the following options: - " & vbCrLf & vbCrLf & tmpmsg
End If


End Function
' -------------------------------------------------------------------------

Then on each check box add an on_click event and call the function, it will check to see if the check boxes have been checked and create a statement which can be used by the msgbox function to notify you of which check boxes have been pressed.

' ------------------------------------------------------------------------
Private Sub Check04_Click()

Call CheckBoxCheck

End Sub
' -------------------------------------------------------------------------

Hope this helps
 
a slight change to vodafrog's code

instead of doing this in the afteupfdate events for each text box

simply set the control source for tmpmsg to

=checkboxcheck(). and this will pull the values in when you click any of the check boxes
 
thank you. I apologize for getting back to this so late.
 

Users who are viewing this thread

Back
Top Bottom