Go Back   Access World Forums > Microsoft Access Discussion > Modules & VBA
 
Reply
 
Thread Tools Rate Thread Display Modes
Old 05-22-2010, 04:21 AM   #1
shmulikharel
Registered User
 
Join Date: May 2010
Posts: 1
Thanks: 0
Thanked 1 Time in 1 Post
shmulikharel is on a distinguished road
Post Send Mail From access (VBA Code)

Okay, after many attempts I managed to create options for sending email via Access:

Is necessary to:
1. Outlook program installed on your computer.
2. Add in the "References" the Type "Microsoft Outlook 12.0 object library" ... See More

To Send a single email:

<StartCode>
Dim olApp As Object
Dim objMail As Object

On Error Resume Next 'Keep going if there is an error


Set olApp = GetObject(, "Outlook.Application") 'See if Outlook is open


If Err Then 'Outlook is not open
Set olApp = CreateObject("Outlook.Application") 'Create a new instance of Outlook
End If

'Create e-mail item
Set objMail = olApp.CreateItem(olMailItem)

With objMail

'Set body format to HTML
.BodyFormat = olFormatHTML
.To = "Your Mail"
.Subject = "Subject"
.HTMLBody = "Text"
.send

End With

MsgBox "Operation completed successfully"

<EndCode>‎

Thanks and good luck everyone!!


Last edited by shmulikharel; 05-27-2010 at 12:23 PM.
shmulikharel is offline   Reply With Quote
The Following User Says Thank You to shmulikharel For This Useful Post:
robhazel (01-22-2013)
Old 11-05-2012, 07:45 AM   #2
mfisk1
Newly Registered User
 
Join Date: Nov 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
mfisk1 is on a distinguished road
Re: Send Mail From access (VBA Code)

Many thanks for posting this bit of code - Ive tried loads and this is definately a nice and simple solution that works

One question.....

If i wanted to insert send text with formatting in the body of the email is it simply a case of inserting the HTML Code where .HTMLBody = "Text"?

Many thanks
mfisk1 is offline   Reply With Quote
Reply

Tags
mail from access

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Command Line Switches KenHigg Access FAQs 1 07-22-2009 05:59 PM
Compacting a ms access 2007 database by vba code odrap Modules & VBA 6 04-04-2009 01:35 AM
Access Excel VBA code from MS Access llkhoutx Excel 0 07-24-2008 04:02 AM
[SOLVED] Word Mail Merge from access vba dates danhur Modules & VBA 1 08-17-2004 08:51 PM
Specify 'From' in VBA code for outlook mail message sariahdog Modules & VBA 5 08-03-2004 10:00 AM




All times are GMT -8. The time now is 06:45 PM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Sponsored Links

How to advertise

Media Kit


Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
(c) copyright 2010 Access World