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 John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

alternative to html emails, format template in access

Status
Not open for further replies.

tonyx666

MIS
Apr 13, 2006
214
GB
i realise that without html emails, the formatting capabilities are very limited.. eg.. you cant use tables or images.. to my knowledge

i believe the alternative is rtf, rich text format, which is just basic text

i have a button on my form that opens outlook and sends an email using the information from my fields.


what i need to know is whether any formatting at all can be added.. in access.. that will jazz up the outlook template even a little bit...

for example.. below is the code for my button.. is there any tags i can add to format the font..

like html tags.. <arial><10pt><blue><bold>"Name: " & Me.Myfield....

i know these tags are non existent, but i just wanted to illustrate what im looking for.. if this can be done.. i would like to see an example of the code, so atleast i can freely add some formating to different paragraphs in my email body..

here is the code at the moment..

Code:
Option Compare Database

Private Sub emailbutton_Click()
On Error GoTo send_Err


Dim strToWhom As String
Dim strMsgBody As String
Dim strSubject As String
Dim temp As Integer

temp = Right([jobday], 1)

strSubject = "Email Title"

If Len(Me.emailadd & vbNullString) = 0 Then
    MsgBox ("Forgot an email address")
    Me.emailadd.SetFocus
Else
    strToWhom = Me.emailadd
    strMsgBody = "How can i format this text"

DoCmd.SendObject , , , strToWhom, , , strSubject, strMsgBody, True
End If

send_Err:
If Err.Number = 2501 Then
MsgBox "THIS EMAIL HAS NOT BEEN SENT!", vbInformation, "Notice!"
End If
End Sub

London Heathrow Cars
 
Is using Outlook rather than SendObject an option for you? If so, you can use all the HTML tags you wish with Outlook's HTMlBody.

Code:
Private Sub SendEmail()
'References: Oulook Library
Dim strEmail, strSubject As String, strBody As String
Dim objOutlook As outlook.Application
Dim objEmail As outlook.MailItem

Set objOutlook = CreateObject("Outlook.application")
Set objEmail = objOutlook.CreateItem(olMailItem)

strEmail = " a @ b.c"
strBody = "Make this <B>bold</B> and <BR>add a line."
strSubject = "Subject"
With objEmail
    .To = strEmail
    .Subject = strSubject
    .HTMLBody = strBody
    '.Send 'Will cause warning message
    .Display
End With

Set objEmail = Nothing
End Sub
 
so are you saying that my current method cannot allow html tags, and your method can.. and i should use your method..

would this allow me to pretty much recreate html code in access.. eg.. add tables.. images.. and all the rest

London Heathrow Cars
 
Another way is to play with a Report.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
im trying to do this.. so this new method shown to me is activated when my button is clicked but it says

user defined type not defined
Code:
Option Compare Database

Private Sub emailbutton_Click()
'References: Oulook Library
Dim strEmail, strSubject As String, strBody As String
Dim objOutlook As outlook.Application
Dim objEmail As outlook.MailItem

Set objOutlook = CreateObject("Outlook.application")
Set objEmail = objOutlook.CreateItem(olMailItem)

strEmail = " a @ b.c"
strBody = "Make this <B>bold</B> and <BR>add a line."
strSubject = "Subject"
With objEmail
    .To = strEmail
    .Subject = strSubject
    .HTMLBody = strBody
    '.Send 'Will cause warning message
    .Display
End With

Set objEmail = Nothing
End Sub

London Heathrow Cars
 
menu Tools -> References ...
tick the Microsoft Outlook Object Library

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
ok cool, now im gettin somewhere.. i know i can be a bit pushy and very persistent..

thank you for this help.. really.. its great to talk to pros so directly like this.

are you telling me that like this.. i can just use ANY html tag i want..

like the img tag.. href.. align.. table cells.. font face.. All of them??

London Heathrow Cars
 
im trying to add a html table and image to my email template in access..

i just need some help getting the syntax correct.. if you can infact include tables and images in this code.. once im shown the correct way to do it once i should be ok..

here it is anyway.. it is wrong

Code:
Private Sub emailbutton_Click()
'References: Oulook Library
Dim strEmail, strSubject As String, strBody As String
Dim objOutlook As Outlook.Application
Dim objEmail As Outlook.MailItem

Set objOutlook = CreateObject("Outlook.application")
Set objEmail = objOutlook.CreateItem(olMailItem)

strEmail = Me.emailadd
strBody = "<table border="0" id="table1" cellspacing="0" cellpadding="0"><tr> & _
        <td><img border="0" src="[URL unfurl="true"]http://www.londonheathrowcars.com/emaillogo.gif"[/URL] width="560" height="113"></td> & _
    </tr></table>" & _
"Make this <B>bold</B> and <BR>add a line."
strSubject = "Subject"
With objEmail
    .To = strEmail
    .Subject = strSubject
    .HTMLBody = strBody
    '.Send 'Will cause warning message
    .Display
End With

Set objEmail = Nothing
End Sub

London Heathrow Cars
 
Do not use double quotes within strings, do use double quotes at the beginnings of line. I wonder about your image source.

[tt]strBody = "<table border='0' id='table1'cellspacing='0' cellpadding='0'><tr>" _
& "<td><img border='0' src=' width='560' height='113'></td>" & _
"</tr></table>" & _
"Make this <B>bold</B> and <BR>add a line."[/tt]

It is possible to include a report as body text in an email:
Access Report as Email Body
thread705-1114129
 
a question:

why does this line end with the following

Code:
"<table border='0' id='table1'cellspacing='0' cellpadding='0'><tr>" [b]_[/b]

and the next line begins and ends with the following

Code:
[b]&[/b] "<td><img border='0' src='[URL unfurl="true"]http://www.londonheathrowcars.com/emaillogo.gif'[/URL] width='560' height='113'></td>" [b]& _[/b]

and this line is like this..

Code:
"</tr></table>" & _

now i remember you told me that & _ is a new line.. what i need to know is why the first two sentences dont both begin and end in the same way.. sorry to be this picky but it will save my time in the long run if i know why.

London Heathrow Cars
 
Because I usually write
_ <next line> &
but you write
& _ <next line>
and I only changed the lines that were missing quotes.
 
ok... already im coming across problems..

i am trying to do things in this way..

"<table> blabla html code.. this and that" & _
"<html. more html here and this and that" & _

and so on.. but it doesnt seem to be working..

here is one table on one line that is showing in red.. and not executing..

i assumed that as long as all the html is in between the " and " tags on a line.. you can put anything you like.. is this correct??

here is the line of code that is causing me trouble.

are the additional " in the code causing these errors??

Code:
strBody = "<table border="1" width="550" id="table1" cellspacing="0" cellpadding="5" bordercolor="#5A79B5"><tr><td>&nbsp;</td></tr></table>" & _

London Heathrow Cars
 
YES i think i have cracked it.. thank you.. i will show you my end result to prove that i have learned and re-inforce the power of the forum and human co-operability

London Heathrow Cars
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top