Question : How do I dedupe a table and create a new table by combining the dupes into a single record?

Hello Experts,
I have a Microsoft Access 2007 database with a table containing duplicate addresses. I need to create a new table that eliminates the duplicate addresses but collects the names from the records that would be deleted and put into a single record. So the resulting table sometimes could have only 1 or 2 Name fields and sometimes may have 4 or 5 or more Name fields. Also when creating the new table I need to concatenate the names.
Not really sure how to do this... Any help would be fantastic.

So the original table would have a few records like this:
first_name, last_name, address, csz
Joe, Smith, 1234 Street, Palm Beach FL 32654
Patty, Jones, 1234 Street, Palm Beach FL 32654
Kevin, Downs, 1234 Street, Palm Beach FL 32654
Bill, Townsend, 4354 Lane, New York NY 12345
Jane, Adams, 4354 Lane, New York NY 12345

The output table should look like this:
full_name1, full_name2, full_name3, address, csz
Joe Smith, Patty Jones, Kevin Downs, 1234 Street, Palm Beach FL 32654
Bill Townsend, Jane Adams,,4354 Lane, New York NY 12345

Answer : How do I dedupe a table and create a new table by combining the dupes into a single record?

Then just build a temporary table that holds ALL the names in a single field, along with an address:

Currentdb.Execute "Select Address, csz INTO YourTempTable FROM Select Distinct Address, csz FROM YourExistingTable"

Now add a SendTo field:

Currentdb.Execute "ALTER TABLE YourTempTable ADD COLUMN SendTo TEXT(255)"

Now build a recordset where you can loop through all names for a specific Address + csz, and concatenate the names:

Dim rst As DAO.Recordset
Dim rstNames as DAO.Recordset
Dim sNames as String

set rst = Currentdb.OpenRecordset("SELECT * FROM YourTempTable")

Do Until rst.EOF
  Set rstNames = Currentdb.Openrecordset("SELECT * FROM YourExistingTable WHERE [Address]='" & rst("Address") & "' AND csz='" & rst("csz") & "')"
  sNames = ""
  Do until rstNames.EOF
    sNames = sNames & vbCrLf & rstNames("First_Name") & " " & rstNames("Last_Name")
    rstNames.movenext
  Loop
  rst.Edit
  rst("SendTo") = sNames
  rst.Update
Loop
Random Solutions  
 
programming4us programming4us