Go Back   Access World Forums > Microsoft Access Discussion > Modules & VBA

 
Reply
 
Thread Tools Rating: Thread Rating: 2 votes, 5.00 average. Display Modes
Old 05-22-2010, 04:21 AM   #1
shmulikharel
Registered User
 
Join Date: May 2010
Posts: 1
Thanks: 0
Thanked 2 Times 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 2 Users Say Thank You to shmulikharel For This Useful Post:
grahamvb (09-21-2013), 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
Old 10-19-2013, 01:22 AM   #3
shutzy
Newly Registered User
 
Join Date: Sep 2011
Location: Wesham, Lancashire, UK
Posts: 758
Thanks: 104
Thanked 2 Times in 2 Posts
shutzy is on a distinguished road
Re: Send Mail From access (VBA Code)

i have just used this code to send 2 emails with a simple text message in the body to try it out.

i am wanting to construct a complete email with images etc. is it possible. i have already tried to use the standard html method in "HTML Body". but the vba code screen has highlighted it in RED.

Code:
.HTMLBody = "<img src="http://www.chrysalis-beauty.co.uk/im...lisbanner4.png" height="120"><br><br>"this is your loyalty points balance."<br><br>"have a nice day!!"
any ideas

__________________
give the man a fish and he will feed for a day, teach the man to fish and he will feed himself for life. everything i know about access is through this forum. thank you
shutzy is offline   Reply With Quote
Old 11-12-2013, 12:29 AM   #4
marlan
Newly Registered User
 
Join Date: Jan 2010
Location: Jerusalm metropolitan
Posts: 185
Thanks: 9
Thanked 7 Times in 7 Posts
marlan is on a distinguished road
Re: Send Mail From access (VBA Code)

Hi there two years later...

you have quotation marks in a string, the compiler thinks the string is closed, led by some other unidentified characters...
concatenate a quotation mark in a string using
Code:
char(43)
witch returns a string of a quotation mark.
marlan is offline   Reply With Quote
Old 11-13-2013, 12:08 AM   #5
elliotgr
Newly Registered User
 
Join Date: Dec 2010
Posts: 67
Thanks: 4
Thanked 1 Time in 1 Post
elliotgr is on a distinguished road
Re: Send Mail From access (VBA Code)

or do this

Code:
strBody = "<html><img src=http://www.chrysalis-beauty.co.uk/im...lisbanner4.png height=120><br><br>this is your loyalty points balance.<br><br>have a nice day</html>"
and then say .HTMLBody = strBody
elliotgr is offline   Reply With Quote
Old 11-13-2013, 06:41 AM   #6
chohan78
Newly Registered User
 
Join Date: Sep 2013
Posts: 41
Thanks: 18
Thanked 0 Times in 0 Posts
chohan78 is on a distinguished road
Re: Send Mail From access (VBA Code)

you can send e-mail with out coding by using macro sendOject.

chohan78 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 10:47 AM.


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 - 2014, Jelsoft Enterprises Ltd.
(c) copyright 2010 Access World