Checkbox check

G

Guest

I have four checkboxes on my form. Before the form is closed, i want to make
sure to check that at least one checkbox has been choosen.

I was able to use this code if only one checkbox is checked but when I add
the AND to check all four, it closes the form without checking. What am i
doing wrong? Any help would be greatly appreciated. Thanks.

If Standard.Value = False And PostChange.Value = False And Emergency.Value =
False And Procedure.Value = False Then
MsgBox "Please select a change type."
End If
 
U

UpRider

Helen, your code requires all 4 checkboxes to be false. Change the AND to
OR.

UpRider
 
F

fredg

I have four checkboxes on my form. Before the form is closed, i want to make
sure to check that at least one checkbox has been choosen.

I was able to use this code if only one checkbox is checked but when I add
the AND to check all four, it closes the form without checking. What am i
doing wrong? Any help would be greatly appreciated. Thanks.

If Standard.Value = False And PostChange.Value = False And Emergency.Value =
False And Procedure.Value = False Then
MsgBox "Please select a change type."
End If

Where did you place the code?
Where in your code does it return to the form so that the user can
enter a check somewhere?

Code Form's Unload event:

Private Sub Form_Unload(Cancel As Integer)
If Standard=0 And PostChange =0 And Emergency = 0 And Procedure = 0
Then
MsgBox "Please select a change type."
Cancel = True
End If

The above Cancel = True will stop the closing of the form.
 
G

Guest

I am running this on the close event.

I tried the code with both zeroes and "false" and i still am able to close
the window when nothing is checked. I want to be prompted if not one of the
checkboxes are checked.
 
G

Guest

I don't want a message if at least one of the boxes are checked. That is
what happens when an OR is used. That is why i choose to use AND. Any other
suggestions? Thanks.
 
F

fredg

I am running this on the close event.

I tried the code with both zeroes and "false" and i still am able to close
the window when nothing is checked. I want to be prompted if not one of the
checkboxes are checked.

Did you not read my entire reply.
Use the Form's UNLOAD event, not the Close event.
 
G

Guest

Yes. I read your reply and I tried it on the unload event and the close
event. I'd rather it be on the close event if possible.
 
F

fredg

Yes. I read your reply and I tried it on the unload event and the close
event. I'd rather it be on the close event if possible.

Helen,
The Close event does NOT allow you to not close the form. It's too
late.
You MUST use the form's Unload event, which does allow you not to
close the form. That's what Cancel = True does.

Read Access Help.
Event + Order of events for database objects +
Order of events for forms and subForms +
Opening and closing a form
 
G

Guest

It has not worked on the unload event.

fredg said:
Helen,
The Close event does NOT allow you to not close the form. It's too
late.
You MUST use the form's Unload event, which does allow you not to
close the form. That's what Cancel = True does.

Read Access Help.
Event + Order of events for database objects +
Order of events for forms and subForms +
Opening and closing a form
 
F

fredg

It has not worked on the unload event.


What do you mean by "it doesn't work"?
Do you get an error?
Does it not fire?
Did you place a breakpoint in the code to see if all of the check box
values are indeed False?

I would suggest you copy and paste the entire Unload sub procedure
into a reply message.
 
G

Guest

Private Sub Form_Unload(Cancel As Integer)
If Standard = 0 And PostChange = 0 And Emergency = 0 And Procedure = 0 Then
MsgBox "Please select a change type."
Cancel = True
End If
End Sub
 
F

fredg

Private Sub Form_Unload(Cancel As Integer)
If Standard = 0 And PostChange = 0 And Emergency = 0 And Procedure = 0 Then
MsgBox "Please select a change type."
Cancel = True
End If
End Sub

The code looks fine.
Place a break point on the If Standard = 0 line.
Open your form and fill it in, but do not place any check marks in any
check box.
Close the form.
The code should stop on that If line. Hover your cursor over Standard,
PostChange, Emergency and Procedure in turn.
The value of each field should appear. Are they each Zero?
They each should be.
Step through each of the lines. the message should appear, then the
form should appear again (when the close is canceled.
 

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