How to validate multiple checkboxes in Access?

Associate
Joined
31 Dec 2002
Posts
458
Hi, for some reason the following VBA code is not working. I have three check boxes and at least one of them must be selected:

If (chk1 + chk2 + chk3) = 0 Then

MsgBox "Please select at least one check box!"
Exit Sub

End If

Any ideas appreciated, this is driving me up the wall as it works on another form in the Before Update event using Cancel = True.

the above code is in the click event of a command button on an unbound form.
 
Associate
OP
Joined
31 Dec 2002
Posts
458
hi thanks for the tips. I have now decided to use a bound form with a sub form. The sub form has the three check boxes now. Do you know how to refer to these on a subform? I know that the main form would be: Me.chk1 ....... but I can see no way to reference a sub form control.
 
Associate
OP
Joined
31 Dec 2002
Posts
458
hi , well I seem to be accessing the control as the message box is displaying when I do not have a check box selected. However after dismissing the messagebox the check box seems to be locked and will not allow me to click it!!!!!! All of the allow edits etc options are set to yes and the control is unlocked. Any ideas?
 
Associate
OP
Joined
31 Dec 2002
Posts
458
sorry must have uploaded the version without the vba in. The code was in the Before Update event of the main form:

If Me!frmContactType.Forms!chkAssociate= 0 And Me!frmContactType.Forms!chkBusiness = 0 And Me!frmContactType.Forms!chkFriend = 0 Then

MsgBox "Please select at least one contact type!"
Exit Sub

End If
 
Associate
OP
Joined
31 Dec 2002
Posts
458
Thanks. I have sorted it now. I am using the Nz function to do the comparison for null value now i.e
if Nz (Me!frmContactType.Forms!chkAssociate, 0) = 0 then
msgbox "Please select a contact type"
cancel = true
end if

Thanks anyway.
 
Back
Top Bottom