Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 16th, 2015, 02:43 PM
Registered User
 
Join Date: Sep 2015
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Sending HTML Email from Access Using a Command Button

I have an access database that we use to process orders. I know how to send emails as an attachment but what we need is to have an HTML email open with specific wording. Below is the code I have entered. Sometimes it sort of works but it opens an email and there is no formatting so the carriage returns are not working. Now I'm getting an error message compile syntax error. Any help would be greatly appreciated.

This is the code...
[code]
Sub SendEmail()

Dim oOutlook As Outlook.Application
Dim oEmailItem As MailItem
'Prevent 429 error, if outlook not open
10 On Error Resume Next
20 Err.Clear
30 Set oOutlook = GetObject(, "Outlook.Application")
40 If Err.Number <> 0 Then
50 Set oOutlook = New Outlook.Application
60 End If

70 Set db = CurrentDb()
80 Set recordset = CurrentData
90 Set MailList = db.OpenRecordset("Email_BO_Qry")
100 Set oEmailItem = oOutlook.CreateItem(olMailItem)
110 Set oOutlookMail = HTMLBody
120 With oEmailItem
130 .To = [Email]
140 .Subject = "Dani Leather USA - Product Back Order"
150 .BodyFormat = olFormatHTML
160 .HTMLBody = _
170 "Thank you for your recent order. Unfortunately, the following item(s) you've ordered are currently not in stock in the NJ warehouse and on order with the tannery." & vbCrLf & _
180 & vbCrLf & _(Color) & vbCrLf & _
190 "Below are a few suggestions we can offer for the back ordered item." & vbCrLf & _
200 & vbCrLf & _"1. We can place the item on back order and deliver your order as soon as we receive it." & vbCrLf & _
210 "2. If this is a stock item, we can check with the tannery for availablity. If it is available, we can have the leather airshipped directly to you (air freight charges may be applied)."& vbCrLf & _
220 "3. We could present you with an alternate similar color." & vbCrLf & _
230 & vbCrLf & _"If you have any questions or you'd like to make a change to your order, please call us. We appreciate your business, and we apologise for any inconvenience this delay causes you."
240 .Display
250 End With
260 Set oEmailItem = Nothing
270 Set oOutlook = Nothing


End Sub


Private Sub Command7_Click()
10 Call SendEmail
End Sub
[code]





Similar Threads
Thread Thread Starter Forum Replies Last Post
ASP: Sending a HTML form to an email address cancer10 Classic ASP Databases 4 February 19th, 2007 05:25 PM
Auto send email from command button underscore10304 Access VBA 3 September 26th, 2006 06:41 AM
Issue sending HTML file as attachment in EMail kdhawan_forum VB Components 0 April 8th, 2005 02:02 PM
Sending email thru Outlook Exp. from VB with html rambhias Beginning VB 6 4 November 22nd, 2004 03:12 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.