I am trying to assign variables value from recordset and insert values into an Access table. I also need to clear the table and insert new set of data before inserting. The recordset is from a stored procedure in SQL Server. Following does not seem to work:
Dim conn As ADODB.Connection, cmd As ADODB.Command, rst As
ADODB.Recordset
Dim Itm As String, JobNo As Integer, RevNo As Integer, DUStatus As Date, LDUStatus As Date, UTrigger As String
Set conn = New ADODB.Connection
conn.ConnectionString = "Provider='sqloledb';Data Source=SERVER;Initial Catalog='Database';Integrated Security='SSPI';"
conn.Open
Set cmd = New ADODB.Command
With cmd
.ActiveConnection = conn
.CommandText = "rg_ItemsQuerySP"
.CommandType = adCmdStoredProc
.Parameters.Append .CreateParameter("@JobNo", adInteger, adParamInput, , TempJobNo)
.Parameters.Append .CreateParameter("@RevNo", adInteger, adParamInput, , TempRevNo)
End With
Set rst = cmd.Execute
If rst.EOF Then Exit Function
rst.MoveLast
rst.MoveFirst
With rst
Do While Not .EOF
Itm = rst.Fields("Item")
JobNo = rst.Fields("Job No")
RevNo = rst.Fields("Revision No")
DUStatus = rst.Fields("DateUpdatedStatus")
LDUStatus = rst.Fields("LastDateUpdatedStatus")
UTrigger = rst.Fields("UpdateTrigger")
DoCmd.RunSQL ("INSERT INTO ItemsQuerySP_Temp values " & Itm & ", " & JobNo & ", " & RevNo & ", " & DUStatus & ", " & LDUStatus & ", " & UTrigger & ";")
rst.MoveNext
Loop
End With
conn.Close
Set conn = Nothing