Instead of looping through the records, I'm getting the same e-mail being sent over and over again. What's wrong with this loop? Thanks
On Error GoTo Error_Handler
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim iCount As Integer
Set db = CurrentDb()
Set rs = db.OpenRecordset("qryPCSTrackerWithin120Days")
With rs
If .RecordCount <> 0 Then
rs.MoveLast
iCount = rs.RecordCount
Do While Not .BOF
DoCmd.SendObject acSendNoObject, , acFormatTXT, Me.SubjectEMail, , , "Personnel Data Discrepancy", "We recently noted the following Personnel data discrepancy", False
.MovePrevious
Loop
End If
End With
rs.Close
Error_Handler_Exit:
On Error Resume Next
Set rs = Nothing
Set db = Nothing
Exit Sub
Error_Handler:
MsgBox "MS Access has generated the following error" & vbCrLf & vbCrLf & "Error Number: " & _
Err.Number & vbCrLf & "Error Source: LoopRecExample" & vbCrLf & "Error Description: " & _
Err.Description, vbCritical, "An Error has Occured!"
Resume Error_Handler_Exit
On Error GoTo Error_Handler
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim iCount As Integer
Set db = CurrentDb()
Set rs = db.OpenRecordset("qryPCSTrackerWithin120Days")
With rs
If .RecordCount <> 0 Then
rs.MoveLast
iCount = rs.RecordCount
Do While Not .BOF
DoCmd.SendObject acSendNoObject, , acFormatTXT, Me.SubjectEMail, , , "Personnel Data Discrepancy", "We recently noted the following Personnel data discrepancy", False
.MovePrevious
Loop
End If
End With
rs.Close
Error_Handler_Exit:
On Error Resume Next
Set rs = Nothing
Set db = Nothing
Exit Sub
Error_Handler:
MsgBox "MS Access has generated the following error" & vbCrLf & vbCrLf & "Error Number: " & _
Err.Number & vbCrLf & "Error Source: LoopRecExample" & vbCrLf & "Error Description: " & _
Err.Description, vbCritical, "An Error has Occured!"
Resume Error_Handler_Exit