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
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