Stopping new record creation

  • Thread starter Thread starter Dan
  • Start date Start date
D

Dan

I have an Order entry form that contains fields for customer name and order
date. It also contains a subform with order details.

I would like to test the customer name and order date and in certain
situations stop it from generating a new record. But it seems like whenever I
tab past one of the order header fields, it automatically generates a new
record. Is there an event handler or method that I can use to do my test and
keep the new record from being generated (rather than letting it be generated
and then deleting it)?

I'm using Access 2007.

Thanks!
 
I think you just want to change the setting of the Form's Cycle property from
All Records, which is the default, to Current Record.
 
Use the form's Before Update event. You can test for missing or incorrect
data and if found can cancel the update:

Form_BeforeUpdate(Cancel As Integer)

If IsNull(DLookup("[CustID]", "tblCustomer","[CustName] = " &
Me.txtCustName)) Then
MsgBox "Customer Not Found"
Cancel = True
End If

If IsNull(Me.txtOrderDate) Then
MsgBox "Order Date Requored"
Cancel = True
End If
End Sub

If the customer is not in the database or no order date has been entered,
the record will not be added to the table.
 
Back
Top