473,595 Members | 2,442 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

What's wrong with my DCount Function?

22 New Member

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
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 1853
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.

Aug 16 '10 #2
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
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

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; oldwindow.close(); } -->
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; a < 5; a++) int strength = int power + int effect; // array of strength
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 wrong????? Function x select case z
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), Day(Me.datetime))) I'm using the above function to count similar records that have fallen in the last year. Ex: SSN datetime cattype # of records in last year
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 control in a subform bound to TableB, Field1B and Field2B are on the form. (Control names are txtField1B and txtField2B)
by: MLH | last post by:
Public Function GetLastDayOfMonth(ByVal dtDay As Date) As Date '************************************************************************** ' Accepts a date. Determines month & year of the date. Returns ' the date of the last day of that month (in the same year) '************************************************************************** GetLastDayOfMonth = DateSerial(Year(dtDay), Month(dtDay), 31) End Function If I enter dtDay value of...
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. #include <time.h> #include <stdio.h> double TimeDifference(struct tm *t1,struct tm *t2) { return difftime(mktime(t1),mktime(t2));
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 = 97.000000
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
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 that line, it is written. i wanna understand what's wrong and fix it, but can't find what is wrong. also this line is mandatory in my code. the code attached is in the link, minimized to the needed info, a bit different then the way it's...
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.