Combine Data from Multiple Fields

KHume

New Member
Joined
Oct 14, 2003
Messages
1
Hello,

I have an Access database with 50+ fields with one field containing a name the remaining fields containg the score for a category. I want to consolidate the data into 3 Fields: Name, Category (contians the Field Heading name) and Score so it will be easier to report on. Does anyone have an idea for a quick way to do this?

Thank you,
Kevin Hume
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Ok, I'm not testing this but what about using VBA:
Go ahead and create the new table first. There are a couple tweakable things still in this code, like using/not using variables to hold some values.

Mike

Code:
Public Function RedesignTable()
Dim dbs As DAO.Database
Dim rs,rs2 As DAO.Recordset
Dim tblname, strSQL, strName As String
Dim X As Integer

Set dbs = CurrentDB

tblName = "put name of your sourcetable here"
strSQL = "Select * from " & tblname
Set rs = dbs.OpenRecordset(strSQL, dbOpenSnapshot)

tblName = "put name of your destination table here"
strSQL = "Select * from " & tblname
Set rs2 = dbs.OpenRecordset(strSQL, dbOpenDynaset)

With rs
  Do Until rs.EOF
    strName = .fields(0).Value
    With rs2
      For X = 1 to rs.fields.count -1
        .AddNew
        .fields(0).Value = strName
        .fields(1).Value = rs.fields(X).Name
        .fields(2).Value = rs.fields(X).Value
        .Update
      Next X
    End With
    .MoveNext
  Loop
End With

Set rs = Nothing
Set rs2 = Nothing
Set dbs = Nothing
End Function
 
Upvote 0

Forum statistics

Threads
1,221,569
Messages
6,160,557
Members
451,656
Latest member
SBulinski1975

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top