View Full Version : find duplicates problem with code


cliff7376
03-19-2002, 01:21 PM
i got this code from this site and i guess i'm not too bright.
If Me.NewRecord Then
If Not IsNull(DLookup("PrimaryID", "TableName", "[PrimaryID] = " & Me.PrimaryID)) Then
MsgBox "This ID already exists"

Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[PrimaryID] = " & Me![PrimaryID]
Me.Undo
Me.Bookmark = rs.Bookmark

End If
End If

my text box name on my form is partnbr and my field name in my table tblpartnbr is called partnbr. I have substiuted these names into this code and i just get a compile error. i would really appreciate some help please.

[This message has been edited by cliff7376 (edited 03-19-2002).]

Jack Cowley
03-19-2002, 05:10 PM
It always helps if you post your code because we can't spot errors if we can't see it. Also, what does the error say? Is partnbr a string or number Data Type?

cliff7376
03-20-2002, 05:17 AM
it is a string

cliff7376
03-20-2002, 05:20 AM
acctually this is the exact code i am using

If Me.NewRecord Then
If Not IsNull(DLookup("partnbr", "tblpartnbr", "[partnbr] = " Me.partnbr)) Then
MsgBox "This ID already exists"

Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[PrimaryID] = " & Me![PrimaryID]
Me.Undo
Me.Bookmark = rs.Bookmark

Jerry Stoner
03-20-2002, 07:24 AM
Set rs = Me.Recordset.Clone
rs.FindFirst "[PrimaryID] = " & Me![PrimaryID]
Me.Undo
Me.Bookmark = rs.Bookmark
Should Be:

Set rs = Me.Recordset.Clone
rs.FindFirst "[partnbr] = " & Me![partnbr]
Me.Undo
Me.Bookmark = rs.Bookmark