Email in VB


Posted by Alan on February 08, 2002 4:23 AM

Hello,
I am having a few problems, I have a report that I want to be able to click on a VB button and it will automatically email it to a designated list of recipents. Thus replacing the need for manual data entry of the addresses. Please help, I tried including the following code, but it didn't work, it kept coming back with Compile Error User defined type not defined"

Dim Address As String
Dim Subject As String
Dim Body As String
Dim Attac As String
Dim strAttachment As String

Set Olapp = CreateObject("Outlook.Application.9")
Set ThisMessage = Olapp.CreateItem(olMailItem)
Set MyAttac = ThisMessage.Attachments

Subject = "February Control Sheet"
Body = "Please see Attached Control Sheet, any problems, please feel free to give me a call"

strAttachment = "C:\WINDOWS\Desktop\Testing\Data.xls"

With ThisMessage
.Recipients.Add "AlanNoble@directcommunications.net"
.Subject = Subject
.Body = Body
Set objOutlookAttach = .Attachments.Add(strAttachment)
.myAttachment = "C:\WINDOWS\Desktop\Testing\Data.xls"
.Send
End With
Set ThisMessage = Nothing
Set Olapp = Nothing

End Sub

Can anyone help me......



Posted by Ivan F Moala on February 09, 2002 3:47 PM

You need to dim all your variables
eg Olapp

AND reference the Outlook Object library.

msooutl9.olb is the Object Library you need


Ivan