Emailing Attachments.... again

rpeare
11-08-2001, 07:20 AM
Howdy all, I found this code posted by sethindeed but it is not working for me. I get the following error as soon as it hits the

.to = ... line
___________
Private Sub Command1_Click()

Dim objOutlook As Outlook.Application
Dim objMailItem As Outlook.MailItem

With objMailItem
.To = "someone@another.com"
.Subject = "Testing Email Attachments"
.Body = "This is the body of this message"
.CC = "someoneelse@another.com"
.Attachments.Add "C:\windows\desktop\test.txt"
End With

objMailItem.Send
Set objMailItem = Nothing
Set objOutlook = Nothing

End Sub
___________

The error I'm getting is:

Runtime Error 91: Object Variable or With Block Variable Not Set

I've got the following reference and component checked off:
Microsoft Outlook Express 5.0 Type Library

I haven't ever tried sending email with code before so I have no idea where to look for the answer.

Thanks for any help you can offer

Banjo
11-08-2001, 07:28 AM
Put this above the With statement:

Set objMailItem = New Outlook.MailItem

rpeare
11-08-2001, 07:32 AM
Ok I inserted the line right after my variable definition and now I get the following error:

Run-Time Error 429: ActiveX component can't create object.

Do I need to have outlook closed before this will fire off correctly or is there some other reference/component I am missing?

rp

Banjo
11-08-2001, 07:36 AM
OK, sorry, you want this:
<pre><font color=blue>Set</font color=blue> objO = <font color=blue>New</font color=blue> Outlook.Application
<font color=blue>Set</font color=blue> objMI = objO.CreateItem(olMailItem)
</pre>

rpeare
11-08-2001, 07:43 AM
Perfect, thanks very much for your quick response banjo. It's very much appreciated.

rp

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum