View Full Version : if any checkbox.value = 1 then


smiler44
02-01-2009, 08:07 AM
can not work out what the correct code should be, but this I what I am trying to do:-

if form1. anycheckbox.value = 1 then
msgbox("hi")
end if

thnaks
smiler44

Uncle Gizmo
02-01-2009, 08:40 AM
I think you would find this thread here Useful in answering this particular question.

Handling Multiple Controls (http://msaccesshintsandtips.ning.com/profiles/blogs/948619:BlogPost:16538)

smiler44
02-01-2009, 10:41 AM
Thank you. Very useful. It took me a few goes but I managed to modify the code to whats below and from that managed to get the code to exit the routine if any checkbox was checked(ticked). Thank you again Smiler44

Private Sub Command1_Click()
' this code will look at checkbox 1 and 2. if one of them is checked then
' a message box is displayed. if both are checked then message box displayed twice
Dim Check1, Check2
Dim checkbox
Dim ctl As Control
For Each ctl In Me.Controls
If TypeOf ctl Is checkbox Then

If ctl.Value = 1 Then MsgBox ("1")

End If
Next ctl
End Sub