Originally Posted by
daniel.preda
Thanks for the advice.
However, I was expecting a solution. The data base is quite huge right now with many tables, relationships, forms and queries... it is out of the question to change anything now. I have to work with what I've got... so... any other ideas.
As a band aide, create a temporary table, run some code to convert the data from "short and wide" to "tall and narrow".
Below is an example of the code. You would have to change some of the variables/ field names (be aware of reserved words)...
Code:
Option Compare Database
Option Explicit
Public Sub TransposeIt()
'assumes that
' "empl' is Text
' "TheData" is Text
' "TheValue" is a Long
' I used "TheData" and "TheValue" as field names because
' I didn't know what your actual field names were
' and to
Dim d As DAO.Database
Dim s As DAO.Recordset
Dim sSQL As String
Dim vEmp As String
Dim vdata As String
Dim vValue As Long
Dim i As Integer 'index for looping
Set d = CurrentDb
'open the source table
sSQL = "SELECT empl, w1, w2, w3 FROM OldTable;"
Set s = d.OpenRecordset(sSQL)
If Not s.BOF And Not s.EOF Then
s.MoveFirst
Do While Not s.EOF
For i = 1 To 3
vdata = "W" & i
vValue = s("W" & i)
sSQL = "INSERT INTO NewTable ( empl, TheData, TheValue )"
sSQL = sSQL & " Values ('" & s("Empl") & "', '" & vdata & "', " & vValue & ");"
d.Execute sSQL, dbFailOnError
Next
'next record
s.MoveNext
Loop
End If
s.Close
Set s = Nothing
Set d = Nothing
End Sub
This seems to work in my test dB.