Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sending Email/Attachments Via VB/Access

Status
Not open for further replies.

JDOne

Programmer
Apr 9, 2003
40
US
Greetings,

I need to send a file as an email attachment. How would I go about this in VB?

Thanks.

J
 
In AccessVBA you may consider the SendObject method.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
What email program are you using?

John

That which does not kill me postpones the inevitable. [thumbsup2]
 
The email program that I'm using is Microsoft Outlook. By any chance, are there any code examples that I can view which address this concern?

Thanks.

J
 
Something like this ?
Dim OA As Outlook.Application
Dim MI As Outlook.MailItem
Set OA = CreateObject("Outlook.Application")
Set MI = OA.CreateItem(olMailItem)
With MI
.To = "somebody@somewhere.com"
.Subject = "Some short info"
.Body = "Some detailed info"
.Attachments.Add "\path\to\file"
.Send
End With

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
I use this functionality with GroupWise, so I don't know syntax for Outlook, but check this link.

Hope that helps.

John

That which does not kill me postpones the inevitable. [thumbsup2]
 
Thanks, all - for your help.

PHV - I tried your code sample but when compiling, received this message:

Compile error:

User-defined type not defined

Looks to me like everything was defined, unless the message is refering to something else?

Please advise.

Thanks.

J
 
You have to reference the Microsoft Outlook Object Library:
while in VBE, menu Tools -> References ...
Or just use late binding, ie replace this:
Dim OA As Outlook.Application
Dim MI As Outlook.MailItem
by this:
Dim OA As Object
Dim MI As Object
Const olMailItem = 0

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
PHV

Thanks for the code. It works. But here's the weird thing. To reiterate, this is a VBAccess app and I added the email code to an existing module. This module queries a database and populates the results in an excel file -- which I wanted to be taken as an email attachment and then sent automatically. The weird thing is when I run the macro which calls the function in which the email code resides, the email and its attachment are sent. But when I run the program from the Macro Scheduler, which causes the app to run at a specific time daily, it completely bypasses the email code while it does the other tasks specified in the program. No errors are being spit out by Access or VB. Don't understand what might be the issue here. Do you have any insight?

Thanks.

J
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top