I need to convert this into query:
The code loops through the recordset and checks to see if the current records NDC is equal to the value of the previous record, If it is set the date to that record to 1 day less than the previous record, if it's not set it to 12/31/9999
The first date it uses (for the first record) is 01/01/1901
The code loops through the recordset and checks to see if the current records NDC is equal to the value of the previous record, If it is set the date to that record to 1 day less than the previous record, if it's not set it to 12/31/9999
The first date it uses (for the first record) is 01/01/1901
Code:
Dim rst As Recordset
Dim strSQL As String
Dim tempNDC As String
Dim tempDATE As Date
Dim TotalCount As Double
DoEvents
strSQL = "SELECT NDC, AWPDate, AWPExp FROM AWP ORDER BY NDC, AWPDate DESC;"
Set db = DBEngine.Workspaces(0).Databases(0)
Set rst = db.OpenRecordset(strSQL)
If rst.RecordCount = 0 Then
MsgBox "No record found"
Exit Function
End If
TotalCount = rst.RecordCount
rst.MoveFirst
tempNDC = ""
tempDATE = #1/1/1901#
Do While Not rst.EOF
'Me.Caption = " processing....." & (Int((rst.AbsolutePosition / TotalCount) * 90) + 10)
rst.Edit
If tempNDC = rst("NDC") Then
rst("AWPexp") = tempDATE - 1
Else
rst("AWPexp") = #12/31/9999#
End If
rst.Update
tempNDC = rst("NDC")
tempDATE = rst("AWPdate")
rst.MoveNext
Loop
'Me.Caption = " processing.....100%"