473,399 Members | 4,192 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Checking for duplicate entries

Hi everyone,

I have a database I'm helping set up for a Charity - I'd like to create a query where if the admin team tries to enter a member twice, a pop up box will inform them that a member with that information already exists in the database and cancels the record.

Essentially:

After admin enters FirstName, LastName and DOB, the database checks to see if all this information is unique to that one record.

If they are, then proceed, if not, then flag that a user alreadys exists with that info.

Does anyone know if this is doable and also if this is the best way of checking?!

Thanks,

Tony
Feb 12 '07 #1
6 9795
NeoPa
32,556 Expert Mod 16PB
If you have a Form with the data entry facility you can put code in the AfterUpdate event procedures of the three main fields to call another procedure which would check that all fields had been entered. If they had it would use DLookup to check for the pre-existence of a matching record. If found a MsgBox() call could inform the operator to change his entry(ies).
Feb 12 '07 #2
ADezii
8,834 Expert 8TB
If you have a Form with the data entry facility you can put code in the AfterUpdate event procedures of the three main fields to call another procedure which would check that all fields had been entered. If they had it would use DLookup to check for the pre-existence of a matching record. If found a MsgBox() call could inform the operator to change his entry(ies).
NeoPa:
Wouldn't a Composite Primary Key on [LastName], [FirstName], and [DOB] be the most straightforward and foolproof approach?
Feb 13 '07 #3
NeoPa
32,556 Expert Mod 16PB
That protects the data but means handling the situation for the programmer and the operator is more complicated. That should be done too, I would say, but the question was about how to save trying to update it beforehand, if the data was wrong.
Feb 13 '07 #4
Thanks for the info chaps,

I've investigated DLookup and this seems to be the best way forward. I searched the web and found a similar scenario using some DLookup code. Taking what I understood from the person detailing the code, I've mocked up an idea of what I think the code for my scenario should look like:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Date_of_Birth_AfterUpdate()
  2.  
  3.     Dim DupeVal As Variant
  4.     DupeVal = DLookup ("[Surname]" , "[Forename(s)]" , "[Date of Birth]" Like '" & Me!FieldName) & "'"
  5.     If Not (IsNull(DupeVal)) Then
  6.         Cancel = True
  7.         MsgBox "This user already exists"
  8.     End If
  9.  
  10. End Sub
I've tested this and it comes up as a Syntax Error on the DupeVal = DLookup line which isn't suprising!

Could someone point me in the right direction as to what is wrong with this line?!

Thanks for your help in advance!

Tony
Feb 14 '07 #5
NeoPa
32,556 Expert Mod 16PB
DLookup Function
You can use the DLookup function to get the value of a particular field from a specified set of records (a domain). Use the DLookup function in Visual Basic, a macro, a query expression, or a calculated control on a form or report.

You can use the DLookup function to display the value of a field that isn't in the record source for your form or report. For example, suppose you have a form based on an Order Details table. The form displays the OrderID, ProductID, UnitPrice, Quantity, and Discount fields. However, the ProductName field is in another table, the Products table. You could use the DLookup function in a calculated control to display the ProductName on the same form.

DLookup(expr, domain, [criteria])
The DLookup function has the following arguments.

Argument Description
expr An expression that identifies the field whose value you want to return. It can be a string expression identifying a field in a table or query, or it can be an expression that performs a calculation on data in that field. In expr, you can include the name of a field in a table, a control on a form, a constant, or a function. If expr includes a function, it can be either built-in or user-defined, but not another domain aggregate or SQL aggregate function.
domain A string expression identifying the set of records that constitutes the domain. It can be a table name or a query name for a query that does not require a parameter.
criteria An optional string expression used to restrict the range of data on which the DLookup function is performed. For example, criteria is often equivalent to the WHERE clause in an SQL expression, without the word WHERE. If criteria is omitted, the DLookup function evaluates expr against the entire domain. Any field that is included in criteria must also be a field in domain; otherwise, the DLookup function returns a Null.
So, if you have a table called [MyTable] and fields in your table called [FirstName], [LastName] & [DOB] and controls on your form also called [FirstName], [LastName] & [DOB] then you would need something like :
TBC - Will try to get to this later. Must go now and this is worth posting anyway.
Feb 25 '07 #6
NeoPa
32,556 Expert Mod 16PB
So, if you have the setup described in post #6, the following code should work for you.
You will need to change the names of the various items if they are different of course.
Expand|Select|Wrap|Line Numbers
  1. Private Sub FirstName_BeforeUpdate(Cancel As Integer)
  2.   Cancel = DupUser()
  3. End Sub
  4.  
  5. Private Sub LastName_BeforeUpdate(Cancel As Integer)
  6.   Cancel = DupUser()
  7. End Sub
  8.  
  9. Private Sub DOB_BeforeUpdate(Cancel As Integer)
  10.   Cancel = DupUser()
  11. End Sub
  12.  
  13. Private Function DupUser() As Boolean
  14.   Dim strWhere As String
  15.  
  16.   DupUser = False
  17.   If IsNull(Me!FirstName) _
  18.   Or IsNull(Me!LastName) _
  19.   Or IsNull(Me!DOB) Then Exit Function
  20.   strWhere = "(([FirstName]='" & Me!FirstName & "') AND " & _
  21.              "([LastName]='" & Me!LastName & "') AND " & _
  22.              "([DOB]=#" & Format(Me!DOB, "m/d/yyyy") & "#))"
  23.   If Not IsNull(DLookup("[LastName]", _
  24.                         "[MyTable]", _
  25.                         strWhere)) Then
  26.     DupUser = True
  27.     Call MsgBox("This user already exists", _
  28.                  vbExclamation, _
  29.                  "DupUser()")
  30.   End If
  31. End Function
Feb 25 '07 #7

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

Similar topics

0
by: Gary Lundquest | last post by:
I have an application with MS Access 2000 as the front end and MySQL as the back end. All was well until I upgraded the MySQL (Linux) server. The Problem: I insert data into a cumulative table....
1
by: Gary Lundquest | last post by:
It appears to me that MySQL version 4 returns an error messge when doing an Insert that results in duplicate entries. Version 3 did NOT return an error - it dropped the duplicate entries and ran...
1
by: marx | last post by:
I have a bit of a problem and any help would be much appreciated. Problem: I have two dropdown list boxes with same data(all data driven). These are used for two separate entries. For every...
3
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...
5
by: Chris Lasher | last post by:
Hello Pythonistas! I'm looking for a way to duplicate entries in a symmetrical matrix that's composed of genetic distances. For example, suppose I have a matrix like the following: A B ...
5
by: Manish | last post by:
The topic is related to MySQL database. Suppose a table "address" contains the following records ------------------------------------------------------- | name | address | phone |...
1
by: JJ | last post by:
What's best practise in this situation: Upon submitting data input on a detailsview (bound to an objectdatasource), I need to check for a duplicate email address (in an sql database) and present...
6
by: teser3 | last post by:
I have my PHP inserting into Oracle 9i. But how do I prevent duplicate record entries? I only have 3 fields in the insert in the action page: CODE <?php $c=OCILogon("scott", "tiger",...
4
by: ramdil | last post by:
Hi All I have table and it have around 90000 records.Its primary key is autonumber field and it has also have date column and name, then some other columns Now i have problem with the table,as my...
7
by: php_mysql_beginer911 | last post by:
Hi .. i am trying to update a table where if field contents any duplictaed entries than one of the field should be updated with random number which is unique so i can make all entries unique i...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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
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...

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.