473,386 Members | 1,798 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,386 software developers and data experts.

Identifying potential duplicates

1
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 1156
NeoPa
32,556 Expert Mod 16PB
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 Expert Mod 8TB
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 Expert Mod 16PB
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
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
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
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
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
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
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
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
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
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
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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...

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.