473,769 Members | 7,388 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Preventing duplicate contact entries


I am using the following code to validate that the person that is being
entered into the database does not already exist. However wnem I test it
by entering myself as a contact(I first checked that I was indeed NOT in
the database), the message still comes up saying that I am in the
database. what am I doing wrong?

Private Sub txtEmailName_Af terUpdate()
On Error GoTo Err_txtEmailNam e_AfterUpdate
If DLookup("EmailN ame", "Contacts", EmailName = Me >>

txtEmailName.Te xt) > 0 Then
FormattedMsgBox "This person is already in the database. This duplicate
entry will not be added.@The information will now be cleared so that you
may enter new data.@", vbOKOnly + vbInformation, "Duplicate Entry"
cbxFollowedUpBy .Value = ""
cbxFollowUpType .Value = ""
txtspecifyConta cttype.Value = ""
CbxSalutation.V alue = ""
txtFirstName.Va lue = ""
txtLastname.Val ue = ""
cbxCompanyName. Value = ""
cbxPosition.Val ue = ""
txtMobilePhone. Value = ""
txtEmailName.Va lue = ""
txtWorkphone.Va lue = ""
txtWorkext.Valu e = ""
txtFaxNumber.Va lue = ""
End If
Exit_Err_txtEma ilName_AfterUpd ate:
Exit Sub
Err_txtEmailNam e_AfterUpdate:
If Err.Number <> 2001 Then
MsgBox Err.Description
Resume Exit_Err_txtEma ilName_AfterUpd ate
Else
Resume Next
End If
End Sub

thank you

Colin Ward

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #1
3 2179
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

The correct syntax for DLookup() is:

DLookup("EmailN ame", "Contacts", "EmailName= '" & Me!txtEmailName & "'")

You have to enclose criteria in double-quotes and concatenate it with
the value on the form. Since it is a text value you have to surround
the value in the TextBox w/ single-quotes.

But, it would be more correct to use the DCount() function to evaluate
if the return value is > 0:

If DCount("*","Con tacts","EmailNa me='" & Me!txtEmailName & "'") > 0 Then

...

Also, instead of individually clearing the values from all the controls,
you can use Me.Undo.

--
MGFoster:::mgf0 0 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQJLswYechKq OuFEgEQLpAwCeJT uCAXcbpapACSOyR 1R6M9pYwlEAn1Pq
7gs0EHzmvw0FXp1 WxihQscdR
=axnk
-----END PGP SIGNATURE-----
ColinWard wrote:
I am using the following code to validate that the person that is being
entered into the database does not already exist. However wnem I test it
by entering myself as a contact(I first checked that I was indeed NOT in
the database), the message still comes up saying that I am in the
database. what am I doing wrong?

Private Sub txtEmailName_Af terUpdate()
On Error GoTo Err_txtEmailNam e_AfterUpdate
If DLookup("EmailN ame", "Contacts", EmailName = Me >>


txtEmailName.Te xt) > 0 Then
FormattedMsgBox "This person is already in the database. This duplicate
entry will not be added.@The information will now be cleared so that you
may enter new data.@", vbOKOnly + vbInformation, "Duplicate Entry"
cbxFollowedUpBy .Value = ""
cbxFollowUpType .Value = ""
txtspecifyConta cttype.Value = ""
CbxSalutation.V alue = ""
txtFirstName.Va lue = ""
txtLastname.Val ue = ""
cbxCompanyName. Value = ""
cbxPosition.Val ue = ""
txtMobilePhone. Value = ""
txtEmailName.Va lue = ""
txtWorkphone.Va lue = ""
txtWorkext.Valu e = ""
txtFaxNumber.Va lue = ""
End If
Exit_Err_txtEma ilName_AfterUpd ate:
Exit Sub
Err_txtEmailNam e_AfterUpdate:
If Err.Number <> 2001 Then
MsgBox Err.Description
Resume Exit_Err_txtEma ilName_AfterUpd ate
Else
Resume Next
End If
End Sub


Nov 12 '05 #2
ColinWard <je*********@ho tmail.com> wrote in
news:40******** *************@n ews.frii.net:

I am using the following code to validate that the person that
is being entered into the database does not already exist.
However wnem I test it by entering myself as a contact(I first
checked that I was indeed NOT in the database), the message
still comes up saying that I am in the database. what am I
doing wrong?

Private Sub txtEmailName_Af terUpdate()
On Error GoTo Err_txtEmailNam e_AfterUpdate
If DLookup("EmailN ame", "Contacts", EmailName = Me >>
txtEmailName.Te xt) > 0 Then


Your DLookup criteria is missing quotation marks, it should be
"Emailname = '" & me.txtEmailName .value & "'"

Note also that the .text property isn't always available
afterupdate, use it beforeupdate.

Note also that me.undo will reverse all the entries that your user
has made in the current record, much easier to understand and to
maintain than all your .value = "" statements.

Also be aware that me.undo may save you problems with blank
records.

Bob Quintal

FormattedMsgBox "This person is already in the database. This
duplicate entry will not be added.@The information will now be
cleared so that you may enter new data.@", vbOKOnly +
vbInformation, "Duplicate Entry"
cbxFollowedUpBy .Value = ""
cbxFollowUpType .Value = ""
txtspecifyConta cttype.Value = ""
CbxSalutation.V alue = ""
txtFirstName.Va lue = ""
txtLastname.Val ue = ""
cbxCompanyName. Value = ""
cbxPosition.Val ue = ""
txtMobilePhone. Value = ""
txtEmailName.Va lue = ""
txtWorkphone.Va lue = ""
txtWorkext.Valu e = ""
txtFaxNumber.Va lue = ""
End If
Exit_Err_txtEma ilName_AfterUpd ate:
Exit Sub
Err_txtEmailNam e_AfterUpdate:
If Err.Number <> 2001 Then
MsgBox Err.Description
Resume Exit_Err_txtEma ilName_AfterUpd ate
Else
Resume Next
End If
End Sub

thank you

Colin Ward

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


Nov 12 '05 #3
Thanks for your reply. I am currently at home but I will give it a try
monday morning

Colin

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
2340
by: CJM | last post by:
How do people go about preventing the user from submitting a form for a 2nd time? For example, the user submits a form, clicks on the back button, and the submits the form again. I have used various techniques in the past (depending on circumstances) but I'd be interested in the techniques you guys currently use. Thanks --
3
6938
by: andreas.maurer1971 | last post by:
Hi all, since a few years I use the following statement to find duplicate entries in a table: SELECT t1.id, t2.id,... FROM table AS t1 INNER JOIN table AS t2 ON t1.field = t2.field WHERE t1.id < t2.id
18
27719
by: Elroyskimms | last post by:
I have a table using an identity column as its Primary Key and two columns (table reduced for simplicity) EmployeeNumber and ArrivalTime. CREATE TABLE ( IDENTITY (1, 1) NOT NULL , (10) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL , NOT NULL , CONSTRAINT PRIMARY KEY CLUSTERED (
9
14587
by: Catherine Jo Morgan | last post by:
Can I set it up so that a certain combination of fields can't contain the same entries, on another record? e.g. a combination of FirstName/LastName/address? Or FirstName/LastName/phone? Or FirstName/LastName/email? Or is it possible to allow this but to throw up an alert message? Warning that this person is probably already in the database? TIA
3
291
by: ColinWard | last post by:
I am using the following code to validate that the person that is being entered into the database does not already exist. However wnem I test it by entering myself as a contact(I first checked that I was indeed NOT in the database), the message still comes up saying that I am in the database. what am I doing wrong? Private Sub txtEmailName_AfterUpdate() On Error GoTo Err_txtEmailName_AfterUpdate >> If DLookup("EmailName", "Contacts",...
2
3382
by: Allen Anderson | last post by:
Hi, I'm trying to design contact (names and addresses) tables in an Access database. Some of the contacts represent vendors, some are board members of the organization, some are donors, some are neighbors of the organization, some are politicians, etc. Rather than create separate tables for each type of contact, I thought it would be better to have: one table with names/addresses one table with kinds of lists (vendors, board...
5
3993
by: Manish | last post by:
The topic is related to MySQL database. Suppose a table "address" contains the following records ------------------------------------------------------- | name | address | phone | ------------------------------------------------------- | mr x | 8th lane | 124364 | | mr x | 6th lane | 435783 | | mrs x | 6th lane | 435783 |
3
3043
by: humblemally | last post by:
Goodmorning all - I created a form where you enter employee skillsets. There are about 15 different skills and the employees choose the skills they have from the list. I have created a field for each skill in the form. My question is how can I prevent an employee from choosing the same skill in the fields. For example I do not want the employee to be able to fill all the 15 fields with Accounting as his skillset. Once he chooses...
9
4149
by: rjshrader | last post by:
I have a table (tblStatus) with three fields (CustomerID, StatusType and StatusDate). I use an unbound form with three text boxes to enter data into the table when a command button (cmdSave) is clicked. CustomerID, StatusType are values that are manually entered by the user; StatusDate is automatically filled with the current date that the record is saved. I would like to use code behind the cmdSave button to check the table for...
0
10216
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, 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...
0
10049
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 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...
0
8873
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6675
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5310
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...
0
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3965
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
2
3565
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.