I am generating an email that I want to send to all the folks in the Query results from qrySelectForEmail.
I keep getting an error: Object variable or With block not defined
Dim db As Database
Dim strSQL As String
Dim rst1 As Recordset
strSQL = "SELECT eMail, FROM qrySurveyors WHERE (tblSurveyors.[Include?])=Yes;"
Set rst1 = db.OpenRecordset(strSQL)
If rst1.Fields("[Include?]") = 0 Then
GoTo lastline
End If
Set MyOlApp = CreateObject("Outlook.Application")
Set myItem = MyOlApp.CreateItem(O1MailItem)
myItem.Subject = "A copy of the survey you requested"
myItem.Body = "All 4 pages of your recent Rate Classification Survey are attached." & Chr(13) & Chr(13) & "Please let me know if I can help with anything else." & Chr(13) & Chr(13) & " Bill Moomau, 360-902-4774." & Chr(13) & Chr(13)
Set MyAttachments = myItem.Attachments
MyAttachments.Add "C:\Windows\Temp\Page1.pdf"
MyAttachments.Add "C:\Windows\Temp\Page2.pdf"
MyAttachments.Add "C:\Windows\Temp\Page3.pdf"
MyAttachments.Add "C:\Windows\Temp\Page4.pdf"
MsgBox "Done thru here"
'
'
myItem.to = rst1.Fields("eMail")
myItem.Send
MsgBox "This survey has been emailed to the email addresses selected on the Select Email Form. A copy has been saved to your Sent email folder if you'd like to double check or verify."
exit_command878_click:
Exit Sub
Err_Command878_Click:
MsgBox err.Description
Resume exit_command878_click
lastline:
MsgBox "At the end of the code"
End Sub
Suggestions, please?
Thanks,
Dave
I keep getting an error: Object variable or With block not defined
Dim db As Database
Dim strSQL As String
Dim rst1 As Recordset
strSQL = "SELECT eMail, FROM qrySurveyors WHERE (tblSurveyors.[Include?])=Yes;"
Set rst1 = db.OpenRecordset(strSQL)
If rst1.Fields("[Include?]") = 0 Then
GoTo lastline
End If
Set MyOlApp = CreateObject("Outlook.Application")
Set myItem = MyOlApp.CreateItem(O1MailItem)
myItem.Subject = "A copy of the survey you requested"
myItem.Body = "All 4 pages of your recent Rate Classification Survey are attached." & Chr(13) & Chr(13) & "Please let me know if I can help with anything else." & Chr(13) & Chr(13) & " Bill Moomau, 360-902-4774." & Chr(13) & Chr(13)
Set MyAttachments = myItem.Attachments
MyAttachments.Add "C:\Windows\Temp\Page1.pdf"
MyAttachments.Add "C:\Windows\Temp\Page2.pdf"
MyAttachments.Add "C:\Windows\Temp\Page3.pdf"
MyAttachments.Add "C:\Windows\Temp\Page4.pdf"
MsgBox "Done thru here"
'
'
myItem.to = rst1.Fields("eMail")
myItem.Send
MsgBox "This survey has been emailed to the email addresses selected on the Select Email Form. A copy has been saved to your Sent email folder if you'd like to double check or verify."
exit_command878_click:
Exit Sub
Err_Command878_Click:
MsgBox err.Description
Resume exit_command878_click
lastline:
MsgBox "At the end of the code"
End Sub
Suggestions, please?
Thanks,
Dave
Last edited: