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.
 

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

Similar Threads

Slow VBA-Generated SQL Involving Totals Query 9
Automatic record generation 2
Linking forms 3
DoCmd and ListBox events 2
Access 2010 Report Button 0
Subform linked to combo box 2
error trapping 3
Copying records 1

Back
Top