Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checking for duplicates with DLookup 1

Status
Not open for further replies.

sirnose1

Programmer
Nov 1, 2005
133
US
I have a textbox on a form that when you lose focus it checks for duplicate. Works fine EXCEPT: If I type a word with an apostrophe I get a syntax error. "tonys" will work, "tony's" will give me the error. Here is the code.

Criteria = "[Prodres] = '" & Me.[txtprodres] & "'"
If Not IsNull(DLookup("[Prodres]", "tblMain", Criteria)) Then
DoCmd.RunSQL " INSERT INTO tblProdDup(DupRec) VALUES (txtprodres);"
MsgBox " Similar existing record. Please check for duplication
 
Criteria = "[Prodres] = [tt]'"[/tt] & Replace(Me.[txtprodres], [tt]"'", "''") & "'"[/tt]

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top