Email Problem

SteveE

Registered User.
Local time
Today, 21:28
Joined
Dec 6, 2002
Messages
221
Hi I,m trying to utilise some code below which was posted here in 2002 which if I can get it to work will do just what I want, my problem is that when I run it the first part works fine, creates the report but when running on fails with "Object variable or with block not set"

Dont know why wonder if anyone can advise me?
=====================================================

Function email2delivery_email()

On Error GoTo email2delivery_email_Err

Dim strline, strHTML
Dim MyItem As Outlook.MailItem
Dim OL As New Outlook.Application


DoCmd.OutputTo acOutputReport, "Bulk Report", acFormatRTF, "C:\Bulk Report.rtf", False

Open "C:\Bulk Report.rtf" For Input As 1

Do While Not EOF(1)
Input #1, strline
strHTML = strHTML & strline
Loop
Close 1
' If OL2002 set the BodyFormat
If Left(OL.Version, 2) = "10" Then
MyItem.BodyFormat = olFormatHTML
End If
MyItem.HTMLBody = strHTML
MyItem.Display

email2delivery_email_Exit:
Exit Function

email2delivery_email_Err:
MsgBox Error$
Resume email2delivery_email_Exit

End Function
 
It is because you have not set reference to a single email item yet. My guess is that you are trying to create a new email, correct? If so then just add NEW after as in the declaration statement.

Dim myMailItem as NEW Outlook.mailitem

Before the email is sent the user will be prompted to either approve the delivery or deny it.
 
Thanks for the sppedy reply, I am sending a new mail and have as suggested added the NEW I now get "Invalid Use of New Keyword"

It will be me being thick but your help appriciated.

===========================================

Function email2delivery_email()

On Error GoTo email2delivery_email_Err

Dim strline, strHTML
Dim myItem As New Outlook.MailItem
Dim OL As Outlook.Application
 
I appologize you can't use the New keyword with a mailitem. So instead of adding new add this line.

Set myItem= OL.createobject("OutLook.mailitem")

Keep the New keyword in Dim OL as New Outlook.Application though. You had it in your first post but not the second one.
 
Mail Problem

Many thanks for you taking the time and trouble to respond but still getting "Object variable or with block not set". and I I clearly dont understand VB I,m at a loss.

Steve
 
What line is giving you that error? Did you leave New in for Outlook.Application? Can you post your database?
 
Again thanks I have been going through it again and recompiled it and guess what it now goes almost to the end but stops with a "The operation Failed" error.
 
Hi, it just errors now at Set myItem = OL.CreateObject("OutLook.mailitem") when this line is taken out its at. myItem.HTMLBody = strHTML and then it errors as the object not set etc.

Al I want is to send a report via the text of an email body, rather than as an attachment. I had found this code while searching and thought it was what I needed but.!
 

Users who are viewing this thread

Back
Top Bottom