Please help me. I've spent so much time on this troubleshooting and been coding for a couple of years or so. I've coded HTML VBA and straight SQL VBA but got caught up on this one big time. Research is critical in this line of work is important I suppose. I know this is quite simple but tried everything and cant get it write in the SQL VBA portion. I need to be able to add all the rest of the fields in the source table/query to the target table. This could be 6 to as many as 50. So Ideally if the source table has field 4, field 5, field 6, field, 7, I need to be able to add it to the target table as well. The code splits one field into multiple rows from one field but that doesn't necessarily relate to the problem entirely. Thanks.
Here is the code:
Public Sub addToTable()
Dim rstObj As DAO.Recordset, dbObj As DAO.Database
Dim InsertSQL As String
Set dbObj = CurrentDb()
Set rstObj = dbObj.OpenRecordset("Test3 Query")
Do While Not rstObj.EOF
Dim memArr() As String
memArr = Split(rstObj.Fields("ID"), ",")
For i = 0 To UBound(memArr)
InsertSQL = "INSERT INTO Test3Table(ID, PO) VALUES(""" & rstObj.Fields("PO") & """, """ & memArr(i) & """)"
DoCmd.RunSQL (InsertSQL)
Next
rstObj.MoveNext
Loop
End Sub
File attached:
Module 6
Source Table:Test3
Target Table:Test3Table
Query Test 3 Query
Here is the code:
Public Sub addToTable()
Dim rstObj As DAO.Recordset, dbObj As DAO.Database
Dim InsertSQL As String
Set dbObj = CurrentDb()
Set rstObj = dbObj.OpenRecordset("Test3 Query")
Do While Not rstObj.EOF
Dim memArr() As String
memArr = Split(rstObj.Fields("ID"), ",")
For i = 0 To UBound(memArr)
InsertSQL = "INSERT INTO Test3Table(ID, PO) VALUES(""" & rstObj.Fields("PO") & """, """ & memArr(i) & """)"
DoCmd.RunSQL (InsertSQL)
Next
rstObj.MoveNext
Loop
End Sub
File attached:
Module 6
Source Table:Test3
Target Table:Test3Table
Query Test 3 Query