472,958 Members | 1,731 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Merging and deleting duplicate records

Hi,

I have an Access table with a number of records which refer to the
same person but with data in different fields. So for example the
table would look like this:

Name..............Field 1...................Field 2
Fred Smith........Red
John Brown........Blue
Fred Smith...................................Truck
John Brown...................................Car

What I'd like to have is a table with:
Name..............Field 1...................Field 2
Fred Smith........Red.......................Truck
John Brown........Blue......................Car

I'm not sure how to go about merging the data for each name into one
record. There are lots of very helpful posting about using SQL to
delete duplicate but I can't find a posting with addresses this issue.

Any suggestions for merging and purging would be appreciated. I'm
happy to be pointed to VB, SQL or whatever.

Thanks in advance.

Emmett Power
Nov 13 '05 #1
2 5514
Emmett Power wrote:
Hi,

I have an Access table with a number of records which refer to the
same person but with data in different fields. So for example the
table would look like this:

Name..............Field 1...................Field 2
Fred Smith........Red
John Brown........Blue
Fred Smith...................................Truck
John Brown...................................Car

What I'd like to have is a table with:
Name..............Field 1...................Field 2
Fred Smith........Red.......................Truck
John Brown........Blue......................Car

I'm not sure how to go about merging the data for each name into one
record. There are lots of very helpful posting about using SQL to
delete duplicate but I can't find a posting with addresses this issue.

Any suggestions for merging and purging would be appreciated. I'm
happy to be pointed to VB, SQL or whatever.

Thanks in advance.

Emmett Power


I would create a table with all of the fields that will be a "final result".

Then I would create a query and append the name and field1 into the new
table. Then using the following code (modifying my table/field names
with your table/field names) update the table. ASSUMPTION. THere can
be one or many records of the same person but if there is a second
record it is has data for the field and the first is blank....like your
example above.

What it does is scans all fields and updates with data from your
existing current tables. At the end, delete the old table and rename
the new.

Sub td()
Dim tdf As TableDef
Dim fld As Field
Dim dbs As Database
Set dbs = CurrentDb
Dim strSQL As String
Dim sf As String

Set tdf = dbs.TableDefs("CurrentTable")
For Each fld In tdf.Fields
sf = fld.Name
If sf <> "Name" And sf <> "Field1" Then
'Name and Field1 already exist when you created
'the new table. Only update the other fields.
strSQL = "UPDATE NewTable INNER JOIN CurrentTable " & _
"ON NewTable." & sf & " = CurrentTable." & sf & _
" SET NewTable." & sf & " = CurrentTable." & sf & _
" WHERE ((Not (CurrentTable." & sf & ") Is Null));

dbs.Execute strSQL
End If
Next
Set tdf = Nothing

End Sub
Nov 13 '05 #2

Salad,

Thanks for the suggestion. I'll give it a go.

Regards

Emmett
*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 13 '05 #3

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

Similar topics

3
by: Nathan Bloom | last post by:
Hi, I have a data entry form (access 2000) that also allows the user to add, update, and delete records from the form. The Delete action is carried out in an event procedure and has the...
2
by: Ross | last post by:
i have less hair now than i used to...i have a database with many duplicate records in it with only one exception, there is one field with the date it was put in the database and that is different....
1
by: svdh | last post by:
I have posed a question last saturday and have advanced alot in the meantime. But I am still not there Problem is that I try to merging various fields from various tables in one document in Word...
4
by: Newbie | last post by:
Can someone help: Is there a way with ado.net and it's disconnected dataset to delete a record in a table if you can't specify a unique field in an SQL WHERE clause. The current Dbase .dbf...
5
by: Manish | last post by:
The topic is related to MySQL database. Suppose a table "address" contains the following records ------------------------------------------------------- | name | address | phone |...
6
by: write2ashokkumar | last post by:
hi... i have the table values with duplicate records, i want to delete the duplicate records, How to delete the duplicate records? I need the query to delete the duplicate rows Example: ...
4
by: mcca0081 | last post by:
hi - i'm trying to delete one of the duplicate records based on the most current date. here's the code for my access 2000 db. any help would be appreciated!!! - thank you kindly Sub...
1
by: tillmanj | last post by:
I am attempting to clean up some data for migration to a new system, and I am stuck on dealing with duplicated user records. The following fields in tblUser are germane to the problem: UserID:...
1
by: akdemirc | last post by:
Hi, My question is about retrieving single records based on a time column, i mean the result set should not include duplicate rows for a unique time value as an example: A B C ...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.