How do I discard empty new records?

m12lrpv

New member
Local time
Today, 10:40
Joined
May 19, 2009
Messages
2
Hi Guy's,

I've got a form which consists of a combo box and a single page form. The combo box filters the form.
Now some of the fields in the table are set as Required: Yes and I want it to stay that way.

When I choose a value in the combo box that doesn't have any associated records in the table, the form defaults to a new record which is good. That's what I want.

If the combo box is changed without completing the form fields the form tries to save the empty new record which of course fails because of the tables not null constraints.

How do I discard the empty record.

I've tried deleting it with a DoCmd.RunCommand acCmdDeleteRecord but it either errors or does nothing :confused:

I have tried workarounds that involved removing the constraints but then I get empty records inserted into the database and I want that even less than the error messages.

I've tried catching the error but catching doesn't let you discard or ignore the error. It just re-occurs.

There must be some way of getting rid of that error but for the life of me I cant figure it out.

Thanks.
 
Have you tried the Undo command to rollback the addition?
 
I have now.

Worked a treat. Thanks for that.

Here's how it ended up...
Code:
  If (IsNull(Me.Hours_Worked) And _
      IsNull(Me.Job_Number) And _
      IsNull(Me.Cost_Centre_Code) And _
      Me.NewRecord) Then
    If (IsNull(Me.ID) = False) Then
  
        DoCmd.RunCommand acCmdUndo
    End If

  End If
 

Users who are viewing this thread

Back
Top Bottom