G
Guest
I am building a form for the user to create a new record. Because the data
that is entered is for several different tables, none of the fields are
bound. Some of the fields are loaded with default values when the form is
opened (e.g. the IDnumber field is loaded with the next available ID number).
Once the data is entered and the user clicks the 'confirm' button, then I've
got code to parse the data to the various tables.
Now, I want to warn (and prevent) the user from creating a duplicate entry
in one of the tables.
I copied the following code from the Access Help documentation:
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
I used this exact same code (just changed the field and table names). This
works to catch the duplicate entry, but:
The Undo statement does not appear to work. Is this because the txt box is
unbound? If this is the case, how could I modify the code to revert back to
the old value?
Thanks for your help,
KB
that is entered is for several different tables, none of the fields are
bound. Some of the fields are loaded with default values when the form is
opened (e.g. the IDnumber field is loaded with the next available ID number).
Once the data is entered and the user clicks the 'confirm' button, then I've
got code to parse the data to the various tables.
Now, I want to warn (and prevent) the user from creating a duplicate entry
in one of the tables.
I copied the following code from the Access Help documentation:
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
I used this exact same code (just changed the field and table names). This
works to catch the duplicate entry, but:
The Undo statement does not appear to work. Is this because the txt box is
unbound? If this is the case, how could I modify the code to revert back to
the old value?
Thanks for your help,
KB