Problem with reference or ???

WinDancer

Registered User.
Local time
Today, 03:37
Joined
Oct 29, 2004
Messages
290
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
 
Last edited:
It would be helpful if you could indicate which line was flagged when you got the error.

In this line

Set myItem = MyOlApp.CreateItem(O1MailItem)

Should it be O1MailItem(wth a 1) or should you change it to OlmailItem (with an L)
 
This isn't that kind of error- no yellow hightlight where it errs out- I just know the code runs fine until the email creation gets to where the recipients are definedw [or NOT, in this case]

Dave
 
You never set the db variable.
 
I understood from the error that there was a problem with a variable.

I assumed it was in the 'to' code, so I tried just a single email address there instead of the qry reference, but still get the same error.

If you will give me a little more of a hint I will go read some more to fix the error.

Also tried changing the 01 to OL and that didn't help, either.

Thanks,
Dave
 
Hint: read post 4 from Pbaldy. You dim that variable but you never set it (Give it a value)
 
Set rst1 = db.OpenRecordset(strSQL)

db is never set.
 
Set db = CurrentDb()

That was pretty silly..

Thanks,
Dave
 
No problem. It's always the simple things that trip us up.
 

Users who are viewing this thread

Back
Top Bottom