IF Statement - Check for null checkboxes in countinuous form view

J

joecosmides

Hello,

I have a form called UpdateInventoryF. (In it are 3 checkboxes.
NewItem, UsedItem, and RefurbItem.)

That form is set to Continous Forms. As a test I have the following
code in the Form Unload event:

Private Sub Form_Unload(Cancel As Integer)
If Not Me.NewItem Then
MsgBox "No fields can be left blank.", vbOKOnly, "Message."
Exit Sub
End If
End Sub

I'm only using the Me.NewItem for now as a test in my IF statement and
I'll add the other 2 checkboxes with your help.

It works fine but only for one record. If I happen to have, for
example, 10 results on the UpdateInventoryF (continuous form) then the
form closes without displaying the error message for the other 9
records. I want it to check all of the records on the form and pop the
message box if any of the records happen to have a null value in those
checkbox fields. I then want it to not close the form until the user
has corrected the problem which would mean they need to check one of
those 3 boxes. A bonus (but not needed at this point) would be for it
to take the user to the record that needs is throwing the error/Msgbox
and if more than one needs attention then it will do it again and take
them to the next one after they try to close the form again, etc.

Thanks!
 
B

Beetle

First, get rid of the three Yes/No fields and just use one ItemType field
linked to a small table of Item Types. With your current structure, if
someone wants to add or remove any item types in the future, you are
going to have to redesign your table, along with all queries, forms and
reports that are based on it (if you're thinking that *won't* happen, that
means it inevitably *will* happen). If you use the latter approach, all
you will need to do is add or remove a record from the Item Types table.

Second, use the form's Before Update event (instead of the Unload event)
to verify the data;

Private Sub Form_BeforeUpdate (Cancel As Integer)

If IsNull(Me![ItemType]) Then
MsgBox "Plese select an Item Type."
Cancel = True
Me![ItemType].SetFocus
End If

End Sub
 

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