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

Home Posts Topics Members FAQ

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 5542
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 ...
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
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
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
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...
0
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
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...

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.