Using BeforeUpdate on Unbound txt box

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
 
G

Guest

I just realized that I posted this in the wrong group. I keep forgetting
that Access Macros are different from what I commonly think of macros. I'll
post this again in the programming section.

KB
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top