The code below is processing report and then emailing automatically as defined in a table tbl_Email.
The first entry in the tbl_Email is executing correctly. Subsequent entries are emailing but are processing under the first entry's parameters. It appears my rst.MoveNext isn't working as it should.
Any ideas why?
Thanks!
- Tony -
Private Sub cmdEmail_Click()
Dim rst As DAO.Recordset
Dim dbs As DAO.Database
Dim subject As String
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("tbl_Email", dbOpenForwardOnly)
Do Until rst.EOF = True
Dim msgtxt As String
Dim txtdate As String
subject = "Labor Distribution Report"
txtdate = Now()
msgtxt = "***AUTOMATED DISTRIBUTION***" & vbCrLf & vbCrLf & "Report ran at " + txtdate + "." & vbCrLf & vbCrLf & _
"Parameter Definition String: PSID...Division...Entity (G1)...Location (G2)...Department (G3)" & vbCrLf & vbCrLf & _
"The attached report's parameters are: " & _
vbCrLf & vbCrLf & rst!PsidL & "..." & rst!DCL & "..." & rst!G1L & "..." & rst!G2L & "..." & rst!G3L & vbCrLf _
& vbCrLf & rst!PsidH & "..." & rst!DCH & "..." & rst!G1H & "..." & rst!G2H & "..." & rst!G3H
DoCmd.SendObject acSendReport, rst!RptName, rst!Output, rst!EmailName, , , subject, msgtxt, False
rst.MoveNext
Loop
rst.Close
dbs.Close
Set rst = Nothing
Set dbs = Nothing
End Sub
The first entry in the tbl_Email is executing correctly. Subsequent entries are emailing but are processing under the first entry's parameters. It appears my rst.MoveNext isn't working as it should.
Any ideas why?
Thanks!
- Tony -
Private Sub cmdEmail_Click()
Dim rst As DAO.Recordset
Dim dbs As DAO.Database
Dim subject As String
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("tbl_Email", dbOpenForwardOnly)
Do Until rst.EOF = True
Dim msgtxt As String
Dim txtdate As String
subject = "Labor Distribution Report"
txtdate = Now()
msgtxt = "***AUTOMATED DISTRIBUTION***" & vbCrLf & vbCrLf & "Report ran at " + txtdate + "." & vbCrLf & vbCrLf & _
"Parameter Definition String: PSID...Division...Entity (G1)...Location (G2)...Department (G3)" & vbCrLf & vbCrLf & _
"The attached report's parameters are: " & _
vbCrLf & vbCrLf & rst!PsidL & "..." & rst!DCL & "..." & rst!G1L & "..." & rst!G2L & "..." & rst!G3L & vbCrLf _
& vbCrLf & rst!PsidH & "..." & rst!DCH & "..." & rst!G1H & "..." & rst!G2H & "..." & rst!G3H
DoCmd.SendObject acSendReport, rst!RptName, rst!Output, rst!EmailName, , , subject, msgtxt, False
rst.MoveNext
Loop
rst.Close
dbs.Close
Set rst = Nothing
Set dbs = Nothing
End Sub