Question : transpose multiple records into one - too many fields defined?

When running this sub, I get the error "Too many fields defined.", from the line :
CurrentDb.Execute "create table newTblData( " & sFld & sPL & ")"

Where am I going wrong?
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
Sub createFlatTable()
Dim rs As DAO.Recordset, j As Integer, i, sPL As String, sFld
Dim rsMax As DAO.Recordset, rsNew As DAO.Recordset, maxProd
Dim rs1 As DAO.Recordset
Set rsMax = CurrentDb.OpenRecordset("select top 1 count(AssistedPersonID) from AssistNew group by AssistedPersonID order by count(AssistedPersonID) desc")
maxProd = rsMax(0)
For i = 1 To maxProd
    sPL = sPL & "," & "AssistServiceCode" & i & " Text" & "," & "AssistProgramCode" & i & " Text" & ", " & "AssistDateBegin" & i & " text"
Next
    sPL = Mid(sPL, 2)
    sFld = "AssistedPersonID Text,"
If Not IsNull(DLookup("[name]", "msysobjects", "[name]='newTblData'")) Then
    CurrentDb.Execute "drop table newtblData"
End If
CurrentDb.Execute "create table newTblData( " & sFld & sPL & ")"
Set rs = CurrentDb.OpenRecordset("select distinct AssistedPersonID from AssistNew")
Set rsNew = CurrentDb.OpenRecordset("newtbldata")
rs.MoveFirst
Do Until rs.EOF
    Set rs1 = CurrentDb.OpenRecordset("select * from AssistNew where AssistedPersonID='" & rs!AssistedPersonID & "'")
    rsNew.AddNew
    rsNew!AssistedPersonID = rs1!AssistedPersonID
    j = 1
    Do Until rs1.EOF
        rsNew("AssistServiceCode" & j) = rs1!AssistServiceCode
        rsNew("AssistProgramCode" & j) = rs1!AssistProgramCode
        rsNew("AssistDateBegin" & j) = rs1!AssistDateBegin
        j = j + 1
        rs1.MoveNext
    Loop
    rsNew.Update
rs.MoveNext
Loop
rs.Close
rs1.Close
rsNew.Close
rsMax.Close
 
End Sub

Answer : transpose multiple records into one - too many fields defined?

duhh..
should be
check how the strings  sFld and  sPL was created with
debug.print sFld
debug.print sPL

the result will be printed in the Immediate Window
Random Solutions  
 
programming4us programming4us