help with code for checkboxes!!!!!!!

DaniBoy

Registered User.
Local time
Today, 16:55
Joined
Nov 18, 2001
Messages
174
Hello,
I have a form where i have three check boxes. Whe am putting a record in one of the three chkboxes has to be true before I can save the record. I tried some if statements but didnt work. Here is what I tried:
Private Sub Form_beforeUpdate(Cancel As Integer)
If chkNew.Value = False And chkRepair.Value = False And chkChange.Value = False Then
MsgBox "Please Check one of the services", vbCritical
End If
End Sub

When I do it with just one check value I get the msgbox, but it goes to the next record, and when I try it with all the conditions it just dont do anything.

Any ideas? What event do I use? is my code rigght?
Thanks
Daniel
 
Try the following:

Code:
Private Sub Form_beforeUpdate(Cancel As Integer)
If Not me.chkNew And Not me.chkRepair And Not me.chkChange Then
    MsgBox "Please Check one of the services", vbCritical
    Cancel = True
End If
End Sub

HTH
SteveA
smile.gif
 
I tried that code but it didnt work, anymore ideas?!!
Daniel
 
Have you done any back traking? ie: just with one of the checkboxes
Private Sub Form_beforeUpdate(Cancel As Integer)
If chkNew.Value = False
MsgBox "So far so good"
End If
End Sub

Is the fact that the code is 'before update'
maybe the after update somewhere
HTH
Dave
 
would using an option group not solve your problem or are these choices not exclusive?
 
I use a similar code on checkboxes and I called the code from the OnExit event. You might try that...it worked for me.
 
How about

Private Sub Form_beforeUpdate(Cancel As Integer)
If chkNew.Value = False And chkRepair.Value = False And chkChange.Value = False Then
Docmd.cancelevent
MsgBox "Please Check one of the services", vbCritical
Docmd.Gotocontrol "Contorlname"
End If
End Sub
 

Users who are viewing this thread

Back
Top Bottom