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

Home Posts Topics Members FAQ

Identifying potential duplicates

1 New Member
Hi guys,

I am not a VBA programmer, but am trying to help someone out with their database. They have a simple form to add contacts to their contacts table.

I have created the below code that will identify duplicates based on the first name and surname. Ideally, it should be the first initial and surname. I have suggested postcode, but they don't really use postcodes.

At the moment this code will match the first name and surname (if exact) and display the message and give the choice to add new, use existing or cancel and start again.

Except.. the message displays whether a match has been found or not. If a match is found, it will display the address - BUT - it only find one record. So if, for example, there are two or more John Smith's, it will only flag one of them. If you select the option to 'Use Existing' it may just pick another record. However, it doesn't display just how many John Smith's it might have found.

I guess what would be good would be to display a list of John Smith's, so the inputter can either pick one or add the new record anyway.

Equally, if no match was found, then there is no need for the display box.

My Ltd skills have got me this far but I can't seem to improve upon it. If anyone has any ideas, I'd be grateful to hear them.

As indicated, I have made a valiant attempt but a reaching the limit of my powers.

Many thanks for any help.

The code:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_BeforeUpdate(Cancel As Integer)
  2. Dim rs As DAO.Recordset
  3. Dim strSQL As String
  4. Dim iAns As Integer
  5. If Me.NewRecord Then ' only check for new additions
  6.      strSQL = "[Surname] = """ & Me!Surname _
  7.          & """ And [First Name] = """ & Me![First Name] & """"
  8.       Set rs = Me.RecordsetClone ' get the form's recordset
  9.       rs.FindFirst strSQL ' find this person's name
  10.       If rs.RecordCount > 0 Then
  11.       iAns = MsgBox("There is a contact with this name already " _
  12.      & "at " & rs![Address 1] & ", " & rs![Address 2] & ", " & rs!Town _
  13.      & ", " & rs!Postcode _
  14.      & ": Select Yes to add record anyway, No to use existing record, " _
  15.      & "Cancel to erase and start over:", vbYesNoCancel)
  16.     Select Case iAns
  17.        Case vbYes
  18.              ' do nothing
  19.        Case vbNo
  20.              ' jump to the found record
  21.             Cancel = True
  22.             Me.RecordsetClone.RecordCount "[First Name] = """ & Me![First Name] & """ AND [Surname] = """ & Me![Surname] & """"
  23.             Me.Undo
  24.             'see if record was found
  25.             If Not Me.RecordsetClone.NoMatch Then
  26.             'move to record
  27.             Me.Bookmark = Me.RecordsetClone.Bookmark
  28.             End If
  29.        Case vbCancel
  30.             Cancel = True
  31.             Me.Undo
  32.      End Select
  33.   End If
  34. End If
  35. End Sub
May 26 '15 #1
3 1159
NeoPa
32,556 Recognized Expert Moderator MVP
I'm not sure what status RecordsetClone would be in at this stage. How about trying a DLookup() on record source of the form instead?
May 26 '15 #2
Rabbit
12,516 Recognized Expert Moderator MVP
The reason the message always comes up is because you're not filtering the recordset. The find just moves the recordset pointer to that record, it doesn't change the count whatsoever.
May 26 '15 #3
NeoPa
32,556 Recognized Expert Moderator MVP
I'm thoroughly embarrassed that I missed that :-(

Good spot rabbit.
May 27 '15 #4

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

Similar topics

3
2533
by: wxbuff | last post by:
I have a report based on our product names that consists of two parts. Both insert data into a temporary table. 1. A single grouped set of results based on all products 2. Multiple tables based...
6
2371
by: Marlene | last post by:
Hi All I have the following scenario, where I have found all the duplicates in a table, based on an order number and a part number (item).I might have something like this: Order PODate Rec...
1
1701
by: Thelma Lubkin | last post by:
I have a form w/ 11 identical text boxes in each of which user can enter a number between 1 and 11. Each defaults to 0, which I use to flag empty. Each has the 1 to 11 restriction as its validation...
4
1830
by: PaulF | last post by:
How do I identify all of the namespace / prefix pairs associated with an XML document I am reading? Thanks for any help. Paul
3
2161
by: AK | last post by:
Hi Our product uses MS-SQL Server 2000. One of our customer has 10 installations with each installation stroring data in its own database. Now the customer wants to consolidate these databases...
2
1462
by: chudson007 | last post by:
I need help flagging duplicate records in ome tables I have. For example if I have Table1 which conatins Field1, Field2 and Field3 like below Field1 Field2 Field3 Field4 Paul 18 Null ...
7
1769
by: kevin43 | last post by:
I reaaly need some help with this. I'm trying develop a method for listing possible duplicate vendors. The problem is I have tons of legacy vendors that need to be mapped to the current ERP. I...
1
2129
by: tskmjk55 | last post by:
Recently, I have a requirement to develop a vb.net application wherein the input excel sheet data which has an average of 5000 records should be checked for Internal duplicates (duplicates within the...
4
3153
by: livewiremce | last post by:
Hello, I need help to modify a query in MS Access 2010 - I need to find duplicates in where they start with the same 5 letters. I created a regular "find duplicates query" but then I cannot...
0
6960
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
7116
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,...
1
6825
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
5418
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
4857
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
3058
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...
0
1376
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 ...
1
595
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
247
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.