Undo

  • Thread starter Thread starter Jay
  • Start date Start date
J

Jay

I have a form that has first and last name fields. When a
new name is entered, I use the DLookUp method to determine
if the name already exists on the database. If it does, I
display a message asking if the user wants to continue or
to cancel. I've been trying to use Undo to cancel the
entry, but it doesn't seem to work. The odd thing is that
it DOES work in the Immediate window. Help!
 
Use the BeforeUpdate Event.
You can search the Help system of Access, or use the following code (it is
from the Help).

Private Sub ProductName_BeforeUpdate(Cancel As Integer)
If(Not IsNull(DLookup("[ProductName]", _
"Products", "[ProductName] ='" _
& Me!ProductName & "'"))) Then
MsgBox "Product has already been entered in the database."
Cancel = True
Me!ProductName.Undo
End If
End Sub-- Marin KostovMicrosoft Office XP Master Instructor
 
Back
Top