There are a few possible causes to this issue. The first is when you have If rsDatalog1.Fields(Datastamp) >= Now() - 90 Then
DataStamp should be in quotes. You can also reference fields with an ! such as rsDatalog1!Datastamp
.
You shouldn't have your rsDatalog1.close
inside your loop. This will cause it to fail on its next pass since it won't be able to check for end of file.
You only need one loop instead of two.
Your insert statement needs to list the fields that you are inserting before you list out the values that are being inserted.
Private Sub Command22_Click()
Dim dbs As DAO.Database
Dim rsDatalog1 As DAO.Recordset
Dim time As Date
time = Now() - 90
DoCmd.SetWarnings False
DoCmd.Echo False
DoCmd.Hourglass True
Set dbs = CurrentDb()
Set rsDatalog1 = dbs.OpenRecordset("SELECT DateStamp, LocationID, DataType, LogValue FROM DataLog")
Do Until rsDatalog1.EOF
If rsDatalog1.Fields(Datastamp) >= Now() - 90 Then
dbs.Execute "INSERT INTO Archive (DataStamp, LocationID, DataType, LogValue) VALUE ('" & rsDatalog1!DataStamp & "', '" & rsDatalog1!LocationID & "','" & rsDatalog1!DataType & "','" & rsDatalog1!LogValue & "')", dbFailOnError
rsDatalog1.Delete
End If
if rsDatalog1.recordCount <> 0 then
rsDatalog1.MoveNext
end if
Loop
rsDatalog1.close
set rsDatalog1 = nothing
DoCmd.Hourglass False
MsgBox "Finish"
End Sub