I recently converted an Access 97 application to Access 2000 and
unfortunately I'm experiencing some problems. Below is code that I use to
send a report to a select set of users.
Set db = CurrentDb
SSql = "Select Distinct SMTPAddress from PendingExpenseVoucherQuery"
stDocName = "Pending Expense Vouchers" ' Report to be used
Set rc = db.OpenRecordset(SSql)
Do While rc.EOF = False
strSubject = "Pending Expense Vouchers"
strMessage = "The attached Word document contains a list of pending
expense vouchers that have not been formally submitted to a supervisor for
approval"
stFilter = "SMTPAddress = '" & rc![SMTPAddress] & "'"
DoCmd.OpenReport stDocName,
acViewPreview, "PendingExpenseVoucherQuery", stFilter
If SendOutEmails() = True Then
DoCmd.SendObject acSendReport, stDocName, acFormatRTF, rc!
[SMTPAddress], , , strSubject, strMessage, ShowEmails()
End If
DoCmd.SelectObject acReport, stDocName, False
DoCmd.Close
rc.MoveNext
Loop
rc.Close
What usually happens is the code goes through the first time fine and then
the second time through the loop Access generates an error message stating
that it can't find the report that I'm trying to email.
Any help in solving this problem would be greatly appreciated.