Check box Msg for eight boxes on the Unload event.

O

oxicottin

Hello, Im sure this has been asked several times but Im having trouble
figuring this out. I have eight check boxes and one of them has to be checked
before the form is closed. I have used the included code for two boxes in the
unload event on another form and it works great but on my new form I have
eight. What do I need to add to this code to be able to acomplish this task
for eight chk boxes? Thanks!!!!

Private Sub Form_Unload(Cancel As Integer)
If Me!Chk1 = False And Me!Chk2 = False Then
MsgBox "You must fill bla bla bla"
Cancel = True
End If
 
M

Marshall Barton

oxicottin said:
Hello, Im sure this has been asked several times but Im having trouble
figuring this out. I have eight check boxes and one of them has to be checked
before the form is closed. I have used the included code for two boxes in the
unload event on another form and it works great but on my new form I have
eight. What do I need to add to this code to be able to acomplish this task
for eight chk boxes? Thanks!!!!

Private Sub Form_Unload(Cancel As Integer)
If Me!Chk1 = False And Me!Chk2 = False Then
MsgBox "You must fill bla bla bla"
Cancel = True
End If


If Not (Chk1 Or Chk2 Or Chk3 Or . . .) Then
 
A

Allen Browne

Assuming this form is bound, Form_Unload is too late.
The record has already been saved by then.
Use Form_BeforeUpdate instead:

Private Sub Form_BeforeUpdate(Cancel As Integer)
If Me.chk1 + Me.chk2 + Me.chk3 + ... = 0 Then
Cancel = True
MsgBox "You must fill bla bla bla"
End If
End Sub

It relies on the fact that False (unchecked) is zero, whereas True (checked)
is -1. So if summing the boxes gives zero, none are checked.

(Again, I assume these are check boxes are bound to yes/no fields, so they
cannot be null.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top