Rich Text in Outlook Email from Access Form (1 Viewer)

crisb184

Registered User.
Local time
Today, 16:24
Joined
Aug 30, 2013
Messages
29
Hello,

Help Please! I am close to getting code to send an email from access with the body of the email populated with a Rich Text textbox from my access form. The problem I am having is that the body of the email is converted to plain text in Outlook which is creating problems for me. Can someone please help me identify what I can do to convert to rich text or HTML in Outlook? I also want to attach a table that is populated by a query in my application, but i haven't got that far yet. Any help is appreciated.
 

crisb184

Registered User.
Local time
Today, 16:24
Joined
Aug 30, 2013
Messages
29
Here is my code:

Code:
Public Function sendemail()
' On Error GoTo ende
esubject = "" ''' Apply you subject here
sendto = Forms!Escalation![cboSPA] ' apply send to email
ccto = "" ''ccto email
ebody = Forms!Escalation![emailbody] ''' body details
' newfilename = "" ''' location of file
SentOnBehalfOfName = "" '' email id for Sent On Behalf Of Name like 
 
Set app = CreateObject("Outlook.Application")
Set itm = app.createitem(0)
 
With itm
.Subject = esubject
.SentOnBehalfOfName = SentOnBehalfOfName
.To = sendto
.cc = ccto
.body = ebody
' .attachments.Add (newfilename)
.Display
.Send
End With
 
Set app = Nothing
Set itm = Nothing
' ende:
End Function]
 
Last edited:

pr2-eugin

Super Moderator
Local time
Today, 21:24
Joined
Nov 30, 2011
Messages
8,494
Not sure what email CODE you are using/referring to, but if you are using the CODE something similar to what crisb184 has shown use HTML bidy instead of Body..
Code:
.Body = "Bla Bla Bla"
Change it to..
Code:
.HTMLBody = "<P>Bla Bla Bla</P>"
 

crisb184

Registered User.
Local time
Today, 16:24
Joined
Aug 30, 2013
Messages
29
Paul,

You are the man! That would have seriously taken me 3 days of googling.

The last piece to this puzzle is getting the results of my query "qmoreinfo" to populate as an attachment to this email. I am trying to use the .attachments.Add to do this but am coming up empty.

This will hopefully be my last question. :)
 

pr2-eugin

Super Moderator
Local time
Today, 21:24
Joined
Nov 30, 2011
Messages
8,494
You need to export the Query first and then attach the exported Query.. Something like..
Code:
Public Function sendemail()
On Error GoTo ende
    esubject = ""                                             [COLOR=Green]''' Apply you subject here[/COLOR]
    sendto = Forms!Escalation![cboSPA]                         [COLOR=Green]' apply send to email[/COLOR]
    ccto = ""                                                 [COLOR=Green]''ccto email[/COLOR]
    ebody = Forms!Escalation![emailbody]                     [COLOR=Green]''' body details[/COLOR]
    newfilename =[COLOR=Red][B] "C:\Users\userNameIs\someFile.xls"[/B][/COLOR]         [COLOR=Green]''' location of file[/COLOR]
    SentOnBehalfOfName = ""                                [COLOR=Green] '' email id for Sent On Behalf Of Name like[/COLOR]
    
    [COLOR=Red][B]DoCmd.OutputTo acOutputQuery, "qmoreinfo", acFormatXLS, newfilename [/B][/COLOR]

    Set app = CreateObject("Outlook.Application")
    Set itm = app.createitem(0)

    With itm
        .Subject = esubject
        .SentOnBehalfOfName = SentOnBehalfOfName
        .To = sendto
        .CC = ccto
        .HTMLBody = ebody
        .attachments.Add newfilename
        .Display
        .Send
    End With
    Set app = Nothing
    Set itm = Nothing
exitOnErr:
    Exit Function
ende:
    MsgBox "Error (" & Err.Number & ") : " & Err.Description
    Resume exitOnErr
End Function
 

crisb184

Registered User.
Local time
Today, 16:24
Joined
Aug 30, 2013
Messages
29
Paul,

Thanks again, this worked. I think I am where I need to be on this, you have been a life saver.
 

Users who are viewing this thread

Top Bottom