Warn of entry of duplicate data in field on a form

G

Guest

I have a field in my table set to indexed- yes(no duplicates) to prevent
duplicates.the data type is text
On a form used to enter data in this field, I want to warn of a duplicate
entry before
entering any more data in any other fields on the form.
Where can this be done? or what code is required?
 
G

Guest

One way would be to put code in the field's Exit eventHandler along the lines
of

If DCount("yourColName", "YourTable", "yourColName ='" &
yourControlName.Value & "'") > 0 Then
MsgBox yourControlName.Value & " Already Exists", vbOkOnly
Cancel = True
End If

Hope This Helps
Gerald Stanley MCSD
 
G

Guest

Gerald,
Thanks for the reply--I am still doing something wrong. I am getting a
syntax error.
Private Sub IT_Exit(Cancel As Integer)
If DCount("IT","tblDATA","IT='"&IT.Value& "'")>0 Then
MsgBox IT.Value & "Already Exists", vbOKOnly
Cancel = True
End If
End Sub
What am I missing?
 

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