Hi experts,
I want to copy data from one table into another using the following code. Before copy, this codes runs through the objective field and looks for comma (,), when found it splits the word before a comma into a new row in the destination table. However, when I click on the button to run this code, I get this message "Compile Error: Expected user-defined type, not project". I looked around for some help topics but no luck. Could you help me understand what the problem is and the solution?
I want to copy data from one table into another using the following code. Before copy, this codes runs through the objective field and looks for comma (,), when found it splits the word before a comma into a new row in the destination table. However, when I click on the button to run this code, I get this message "Compile Error: Expected user-defined type, not project". I looked around for some help topics but no luck. Could you help me understand what the problem is and the solution?
Code:
Private Sub Command0_Click()
DoCmd.SetWarnings Off
On Error GoTo Error_Resume
Dim db As Database
Dim rs As Recordset
Set db = CurrentDb()
Dim sqlStr, insertSQL, arrayVal As String
Dim TestArray() As String
Dim fieldMechanism, fieldObjectives, fieldProjects As String
Dim i As Integer
sqlStr = "SELECT [Mechanism], [Objectives], [Projects] FROM Tab_ProjectsByObjectives_ForSplitByObjectives"
Set rs = db.OpenRecordset(sqlStr)
rs.MoveLast
rs.MoveFirst
Do While Not rs.EOF
fielMechanism = rs.Fields(0)
fieldObjectives = rs.Fields(1)
fieldProjects = rs.Fields(2)
TestArray() = Split(fielObjectives, ", ")
For i = 0 To UBound(TestArray)
If TestArray(i) <> "" Then
arrayVal = TestArray(i)
insertSQL = "INSERT INTO Tab_ProjectsByObjectives_SplittedByObjectives([Mechanism], [Objectives], [Projects]) " _
& "VALUES(""" & fieldMechanism & """, """ & arrayVal & """, """ & fieldProjects & """)"
DoCmd.RunSQL (insertSQL)
Error_Resume:
Resume Next
End If
Next i
rs.MoveNext
Loop
End Sub