Hi Folks,
I could use a little help with writing values for code comparing current and previous values ...
The code is below:
Option Compare Database
Function runcompare()
Dim rst As Recordset
Dim dbs As Database
Dim querystr As String
Dim qryprev As String
Dim qrycurrent As String
Dim rstcnt As Integer
Set dbs = CurrentDb
querystr = "SELECT subno, c_proc from BaseNormalized;"
Set rst = dbs.OpenRecordset(querystr)
rst.MoveLast
rst.MoveFirst
For rstcnt = 0 To rst.RecordCount - 1
qryprev = rst.Fields("subno").Value
qryprev = qryprev & rst.Fields("c_proc").Value
If rstcnt <> rst.RecordCount - 1 Then
rst.MoveNext
qrycurrent = rst.Fields("subno").Value
qrycurrent = qryprev & rst.Fields("c_proc").Value
'If qryprev <> qrycurrent Then WRITE QRYPREV TO TABLE [DIFFERENCE]
End If
End If
Next rstcnt
rst.Close
dbs.Close
End Function
What I am attempting to do is compare current values in terms of the field subno and the values c_proc to the previous values; and if different, to write that previous value (both subno and c_proc) into a table. I am not quite sure if the above logic is correct, I think it is? But what I know I need help with would be writing the elements to a table ... using the docmd.gotorecord I don't see how I would use that command to actually insert the values of qryprev into a table if qryprev <> qrycurrent. Any help would be greatly appreciated.
Thank you,
Joe
I could use a little help with writing values for code comparing current and previous values ...
The code is below:
Option Compare Database
Function runcompare()
Dim rst As Recordset
Dim dbs As Database
Dim querystr As String
Dim qryprev As String
Dim qrycurrent As String
Dim rstcnt As Integer
Set dbs = CurrentDb
querystr = "SELECT subno, c_proc from BaseNormalized;"
Set rst = dbs.OpenRecordset(querystr)
rst.MoveLast
rst.MoveFirst
For rstcnt = 0 To rst.RecordCount - 1
qryprev = rst.Fields("subno").Value
qryprev = qryprev & rst.Fields("c_proc").Value
If rstcnt <> rst.RecordCount - 1 Then
rst.MoveNext
qrycurrent = rst.Fields("subno").Value
qrycurrent = qryprev & rst.Fields("c_proc").Value
'If qryprev <> qrycurrent Then WRITE QRYPREV TO TABLE [DIFFERENCE]
End If
End If
Next rstcnt
rst.Close
dbs.Close
End Function
What I am attempting to do is compare current values in terms of the field subno and the values c_proc to the previous values; and if different, to write that previous value (both subno and c_proc) into a table. I am not quite sure if the above logic is correct, I think it is? But what I know I need help with would be writing the elements to a table ... using the docmd.gotorecord I don't see how I would use that command to actually insert the values of qryprev into a table if qryprev <> qrycurrent. Any help would be greatly appreciated.
Thank you,
Joe