469,603 Members | 2,049 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,603 developers. It's quick & easy.

What's wrong with my DCount Function?

Hello,

I'm trying to get rid of duplicate entries for contacts. So in my contact entry form when the save buttom is clicked I want to use the DCount function to see if there are duplicates. Here is the code I'm trying to use

Expand|Select|Wrap|Line Numbers
  1. If DCount("*", "contacts", [First_Name] = '" & _ Me.First_Name "' & [Last_Name] ='" & _  me.Last_Name " ') >0 Then
  2. MsgBox "contact already exists"
  3. Else
  4. MsgBox "all good"
  5. End If
  6.  
  7.  
It is not working and I've tried different ways to write it but I can't get it right. My fields are text fields.

Thanks in advance for the help
Aug 16 '10 #1

✓ answered by Stewart Ross

Hi. If you've pasted your code from the actual module and not retyped it then there are some minor errors which are easy to correct. Your IF statement is currently:

Expand|Select|Wrap|Line Numbers
  1. If DCount("*", "contacts", [First_Name] = '" & Me.First_Name "' & [Last_Name] ='" &  me.Last_Name " ') >0 Then
but it should be
Expand|Select|Wrap|Line Numbers
  1. If DCount("*", "contacts", "[First_Name] = '" & Me.First_Name & "' AND [Last_Name] ='" &  me.Last_Name & "'") > 0 Then
Please be aware that having two contacts with the same name is quite a common occurrence and does not mean that they are necessarily duplicates - you could only tell this by looking at additional information which you don't specify here.

-Stewart

2 1632
Stewart Ross
2,545 Expert Mod 2GB
Hi. If you've pasted your code from the actual module and not retyped it then there are some minor errors which are easy to correct. Your IF statement is currently:

Expand|Select|Wrap|Line Numbers
  1. If DCount("*", "contacts", [First_Name] = '" & Me.First_Name "' & [Last_Name] ='" &  me.Last_Name " ') >0 Then
but it should be
Expand|Select|Wrap|Line Numbers
  1. If DCount("*", "contacts", "[First_Name] = '" & Me.First_Name & "' AND [Last_Name] ='" &  me.Last_Name & "'") > 0 Then
Please be aware that having two contacts with the same name is quite a common occurrence and does not mean that they are necessarily duplicates - you could only tell this by looking at additional information which you don't specify here.

-Stewart
Aug 16 '10 #2
Thanks. And I was aware of the possibility of having people with the same first and last name. I'm using the company name as a third variable. So now it looks like so:

Expand|Select|Wrap|Line Numbers
  1. If DCount("*", "contacts", "[First_Name] = '" & Me.First_Name & "' AND [Last_Name] ='" & Me.Last_Name & "' AND [Company] ='" & Me.Company & "'") > 0 Then
  2.  
And it works, so thanks so much for the help Stewart!
Aug 17 '10 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

5 posts views Thread by tin | last post: by
6 posts views Thread by neo88 | last post: by
51 posts views Thread by WindAndWaves | last post: by
1 post views Thread by SheldonMopes | last post: by
6 posts views Thread by sugaray | last post: by
15 posts views Thread by XZ | last post: by
6 posts views Thread by PengYu.UT | last post: by
reply views Thread by guiromero | last post: by
reply views Thread by devrayhaan | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.