Duplicate Entries

L

Louie

I am using the below to avoid duplicate Entries and like others I do not want
to enter all information just to find out that the primary key (which is what
I enter) is duplicated - I have search extensively thru the Answer and
questions. I have found many suggestions and nothing has worked

A problem to include is the field = "DMD#" which is what I used to refer to
the Table field and "DMD_" to refer to the form field (this is what popped up
when I was typing Me.DMD_ so I just left it)

Sorry if I am confusing but I am not good with the programming language


Private Sub DMD__BeforeUpdate(Cancel As Integer)
Dim strMsg As String

If IsNull(Me.DMD_) Or (Me.DMD_ = Me.DMD_.OldValue) Then
'Do nothing: it's not a duplicate of itself.
Else
If Not IsNull(DLookup("DMD#", "2009 DMD's", "DMD# = " " & Me.DMD_))
Then
Cancel = True
strMsg = "You already have that value." & vbCrLf & _
"Enter another value, or press Esc to undo."
MsgBox strMsg, vbExclamation, "Duplicate value!"
End If
End If
End Sub
 
C

Chegu Tom

in the AfterUpdate event of me.DMD_

If nz(dlookup("[DMD#]","2009 DMD's","[DMD#]=" & me.dmd_ & "")>"" then
msgbox "key value already exists"
me.[dmd#].setfocus
endif

be careful using special characters (#$&' etc) in table or field names it
can cause many complications

if DMD#
 

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