Basic DCount Qestion to Check for Duplicates

Bdaviskar

Registered User.
Local time
Today, 07:22
Joined
Aug 16, 2013
Messages
23
Hello, I am having trouble with the syntax for a DCount function for an If then Statement to prevent duplicate data.

I have searched the forum and the web but the more I look, the more confused I get. :banghead: However I am a lot closer.....

I have a text box on a form to input a text value. I want to write a macro that will use the Dcount function to check for duplicate records when the text box loses focus or before change event.

I do have “no duplicates” at the table level but I want to catch it right away to alert the user.

This is what I have in my If Then Statement but I can’t seem to get it correct.

Dcount(“*”,”tblSession”,”[SessionID]=’ & [Forms]![frmSession]![Sessionid]’”)>0

I think my issue is in my criteria section. Any help is appreciated. Thank you in advance.
 
You need to leave the field reference outside of your quotes. Try:
Code:
DCount("*","tblSession","[SessionID] = '" & [Forms]![frmSession]![Sessionid] & "'") > 0
Also I'm not sure if the smartquotes are valid or not...
 
Last edited:
Thank you That work!
 

Users who are viewing this thread

Back
Top Bottom