Not Looping through a Recordset

Novice1

Registered User.
Local time
Yesterday, 16:31
Joined
Mar 9, 2004
Messages
385
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
 
perhapsifyoucoudlbebotheredtousecodetagstopreserveindentingicouldbebotheredtotryandreaditandprovideananaswer
 
You're using a value from the form instead of one from the recordset, like:

rs!EmailAddress
 
I'm sorry I don't understand. Still getting the first record sent over and over again.


Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim iCount As Integer

Set db = CurrentDb()

Set rs = CurrentDb.OpenRecordset("qryPCSTrackerWithin120Days")

If rs.RecordCount <> 0 Then
rs.MoveFirst
While Not rs.EOF

DoCmd.SendObject acSendNoObject, , acFormatTXT, Me.SubjectEMail, , , "Personnel Data Discrepancy", "We recently noted the following Personnel data discrepancy", False

rs.MoveNext
Wend
End If

rs.Close
Set rs = Nothing
 
This refers to the form, so won't change:

Me.SubjectEMail
 
How do I refer back to the record set so it can cycle through?
 
Like I showed in post 3.
 
Can I use a recordset to find blank fields? The attempt below generated a 2465 error (can't find field)?


Set db = CurrentDb()
Set rs = db.OpenRecordset("qryPCSTrackerWithin120Days")

With rs
If .RecordCount <> 0 Then
rs.MoveLast
iCount = rs.RecordCount

Do While Not .BOF

If IsNull([rs!SubjectEMail]) Then MsgBox "Missing e-mail", vbOKOnly, "Fix Record"

.MovePrevious
Loop
End If
End With

rs.Close
 
Is that the correct field name, and is it included in the query?

I'd open the recordset on an SQL statement that only pulled records with no email.
 

Users who are viewing this thread

Back
Top Bottom