primary key violaton

  • Thread starter Thread starter Newbie
  • Start date Start date
N

Newbie

I have a form with some validation before the record is updated to let the
user know that the record can't be saved.

How can I get rid of the data that has been entered when the validation
fails?

If I try and delete the record I can't because it hasn't yet been entered
into the table but I can't enter it into the table because the data isn't
correct.
I have tried docmd.runcommand acCmdUndo but that doesn't work either

The primary key is JobNo
In the before update of this field it checks to see if it already exists in
the table
In the before update of the form it checks that all the fields have valid
entry

What do I need to do . . . . .
 
Newbie said:
I have a form with some validation before the record is updated to
let the user know that the record can't be saved.

How can I get rid of the data that has been entered when the
validation fails?

If I try and delete the record I can't because it hasn't yet been
entered into the table but I can't enter it into the table because
the data isn't correct.
I have tried docmd.runcommand acCmdUndo but that doesn't work either

The primary key is JobNo
In the before update of this field it checks to see if it already
exists in the table
In the before update of the form it checks that all the fields have
valid entry

What do I need to do . . . . .

To cancel the update of a control and set it back to its previous value,
use the BeforeUpdate event of the control, set the event procedure's
Cancel argument to True, and call the control's Undo method:

Private Sub txtMyTextbox_BeforeUpdate(Cancel As Integer)

If <some condition is true> Then
MsgBox "I'm sorry, Dave, I can't do that."
Cancel = True
Me!txtMyTextbox.Undo
End If

End Sub

To cancel the update of the current record and reverse all changes to
it, use the BeforeUpdate event of the form, set the event procedure's
Cancel argument to True, and call the form's Undo method:

Private Sub Form_BeforeUpdate(Cancel As Integer)

If <some condition is true> Then
MsgBox "Fuhgeddaboutit!"
Cancel = True
Me.Undo
End If

End Sub
 
Back
Top