Set field to Null after bad value

  • Thread starter Thread starter hotplate
  • Start date Start date
H

hotplate

I am using a scanner to input a serial number. I have a valadation of
10 digits, so if it is wrong, they have to enter it again. How would I
reset the value back to null on a bad scan? Here is my code on after
update:

If Len([Serial]) <> 10 Then
MsgBox "Serial number is incorrect" _
, vbCritical, "Re-Enter Serial"
Me.Serial.SetFocus
End If

I tried Undo but that didnt work. Should it be a before update?

James
 
hotplate said:
I am using a scanner to input a serial number. I have a valadation of
10 digits, so if it is wrong, they have to enter it again. How would I
reset the value back to null on a bad scan? Here is my code on after
update:

If Len([Serial]) <> 10 Then
MsgBox "Serial number is incorrect" _
, vbCritical, "Re-Enter Serial"
Me.Serial.SetFocus
End If

I tried Undo but that didnt work. Should it be a before update?

James
Hi James,
yes put your code in before update event
and add:
Cancel = true
after the messageBox

Bye
 
hotplate,
Use the BeforeUpdate event. It has a Cancel capability.
Try this...

Private Sub YourField_BeforeUpdate(Cancel as Integer)
If Len([Serial]) <> 10 Then
MsgBox "Serial number is incorrect", vbCritical, "Re-Enter Serial"
Cancel = True
YourField.Undo
End If
 
Back
Top