No Duplicates

D

Don Rountree

I have a table with ITEM_NO as the indexed field - with no duplicates. I have a form set up so that new items can be set up. The table's name is tblITEM. Will someone show me how to write a code that will clear the ITEM_NO field and reset the focus if they key in a duplicate item number? I'm sure it is easy, but I can't figure it out. I'd also like to have an error message indicating the duplicate number appear. I'd appreciate any help. Thanks..

Don Rountree
 
T

tina

violating a field's unique index in the form's underlying table
automatically causes a form-level error. in the form's OnError event, add an
event procedure to trap and handle the error, as

Private Sub Form_Error(DataErr As Integer, Response As Integer)

If DataErr = 3022 Then
Response = acDataErrContinue
With Me!ITEM_NO
MsgBox .Value & " is already being used. Enter another " _
& "item number, please."
.Value = Null
.SetFocus
End With
End If

End Sub

recommend you read the OnError Property topic and the Error Event topic in
Access Help, so you'll understand how the code works.

hth


Don Rountree said:
I have a table with ITEM_NO as the indexed field - with no duplicates. I
have a form set up so that new items can be set up. The table's name is
tblITEM. Will someone show me how to write a code that will clear the
ITEM_NO field and reset the focus if they key in a duplicate item number?
I'm sure it is easy, but I can't figure it out. I'd also like to have an
error message indicating the duplicate number appear. I'd appreciate any
help. Thanks...
 

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