473,473 Members | 1,936 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

What's wrong with my DCount Function?

22 New Member
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
2 1837
Stewart Ross
2,545 Recognized Expert Moderator Specialist
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
flower88
22 New Member
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

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

Similar topics

5
by: tin | last post by:
<script language="Javascript"> <!-- function apri (theURL,winName,features){ window.open (theURL,winName,features); var a=null; oldwindow = window.self; oldwindow.opener = window.self;...
6
by: neo88 | last post by:
hi guys Can anyone please tell me what is wrong with this function: inline int strength(void) { int a; // tests to see what strength value the agent just attacked\defended with for (strength;...
51
by: WindAndWaves | last post by:
Can anyone tell me what is wrong with the goto command. I noticed it is one of those NEVER USE. I can understand that it may lead to confusing code, but I often use it like this: is this...
1
by: Dan Leeder | last post by:
stroccur = DCount("", "empnotes", " = " & Chr(34) & Me.Rpt_Card_Type & Chr(34) & " And = " & Me.SSN & " And #" & & "# > " & DateSerial(Year(Me.datetime) - 1, Month(Me.datetime),...
1
by: SheldonMopes | last post by:
I'm having difficulty with the DCount function, not getting the results that I want. Field1A and Field2A are fields in TableA matching Field1B and Field2B in TableB Using a calculated...
7
by: MLH | last post by:
Public Function GetLastDayOfMonth(ByVal dtDay As Date) As Date '************************************************************************** ' Accepts a date. Determines month & year of the date....
6
by: sugaray | last post by:
hi, below is my program for doing exercise with library time functions, something is not right with it, and for the time being i couldn't figure out what's wrong and where, thanx for your help. ...
15
by: XZ | last post by:
Hi everyone, this is really confusing to me: #include <stdio.h> main(int argc, char **argv) { printf("argv = %f\n",(double)atof(argv)); printf("argv = %d\n\n",atoi(argv)); } $ a.out a argv...
6
by: PengYu.UT | last post by:
Hi, I couldn't see what is wrong with the following program. Would you please help me? Thanks, Peng g++-3.4 -MM -g main.cc .dep
4
by: hirsh.dan | last post by:
i have a functions that writes information to a file. inside that function i have a line in which i call another function. if this line is executed, nothing is written to the file, but if i remark...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.