R
Rhys Davies
Hi, im trying to loop through a recordset and insert the contactID and
current date/time into a table. The query has 150 rows for example, after i
run this code the table has the 150 rows in there with the correct date/time
but the contactID is the same for each row in the table, namely the opening
record in the query, so it seems to loop through the records in a way but
doesnt move to the next record before running the INSERT code.
Can anyone point out where im going wrong?
Thanks.
Dim rsdbase As Database
Dim rstemp As Recordset
Set rsdbase = CurrentDb
Dim strSQL As String
Set rstemp = rsdbase.OpenRecordset("SELECT [contactID] FROM
[qrycompanycontacts]")
DoCmd.SetWarnings False
Do Until rstemp.EOF
strSQL = "INSERT INTO tblmailinghistory([userID],[date])" & _
"SELECT" & "'" & contactID & "'," & _
"'" & Now & "'"
DoCmd.RunSQL strSQL
rstemp.MoveNext
Loop
DoCmd.SetWarnings True
End Sub
current date/time into a table. The query has 150 rows for example, after i
run this code the table has the 150 rows in there with the correct date/time
but the contactID is the same for each row in the table, namely the opening
record in the query, so it seems to loop through the records in a way but
doesnt move to the next record before running the INSERT code.
Can anyone point out where im going wrong?
Thanks.
Dim rsdbase As Database
Dim rstemp As Recordset
Set rsdbase = CurrentDb
Dim strSQL As String
Set rstemp = rsdbase.OpenRecordset("SELECT [contactID] FROM
[qrycompanycontacts]")
DoCmd.SetWarnings False
Do Until rstemp.EOF
strSQL = "INSERT INTO tblmailinghistory([userID],[date])" & _
"SELECT" & "'" & contactID & "'," & _
"'" & Now & "'"
DoCmd.RunSQL strSQL
rstemp.MoveNext
Loop
DoCmd.SetWarnings True
End Sub