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

Underline Text 3

Status
Not open for further replies.

snoopy80

Technical User
Jun 27, 2001
106
Hello,
I have a send button in a form when clicked it put some text information on an Outlook email so I can email it. My question is is there a way I can underline or bold part of text body? Here is the body of my email:

strBody = strBody & "UserName: " & Me!UserName & vbCrLf & vbCrLf
strBody = strBody & "Insurance: " & Me!InsuranceName & vbCrLf & vbCrLf
strBody = strBody & "Department: " & Me!Department & vbCrLf & vbCrLf & vbCrLf

strBody = strBody & "Comments: "

For Example, I want to Underline or Bold UserName, Insurance, Department, and Comments.
Appreciate any help. Thanks.
 
Use the HTMLBody property of the MailItem object and put appropriate tags:
strBody = strBody & "<u>UserName</u>: <b>" & Me!UserName & "</b><p>"

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Not using a plain text e-mail unfortunately.

To achieve this I would produce a HTML email (using correct HTML tags) and assign that to the HTMLBody property (assuming you're using Outlook automation that is), this also allows a more flexible approach should you need to do anything a bit more complicated later on.

HarleyQuinn
---------------------------------
The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little. - Joe Martin

Get the most out of Tek-Tips, read FAQ222-2244 before posting.

 
Thanks PHV and HarleyQuinn for your replies.
I have been trying to create an HTML email from Access but have been unsuccessful. Does anyone know a link to some Examples I can learn from? Thanks in advance.
 
you have to build the email body string as a complete HTML document ie
Code:
strbody ="<html><head></head><body>"
strbody=strbody+"Heres some <u>underlined</u> text heres some <b>bold</b>" 
strbody=strbody+"</body></html>"
Havent got any complete vba examples to hand - in .net
Code:
            Dim insMail As New MailMessage()
            With insMail
                .From = mailaddress
                .To.Add(strToAddress)
                .Subject = Trim(strSubject)
            [b]    .IsBodyHtml = true [/b]
                .Body = Trim(strBody)

H
 
Thanks Huggyboy for your post. Here is what I tried:

Private Sub CmdSend_Click()

Dim objmailitem As Outlook.MailItem
.
. 'All Declarations

strHTMLbody = ""
strHTMLbody = strHTMLbody & "<html>" & vbCrLf
strHTMLbody = strHTMLbody & "<head></head>" & vbCrLf
strHTMLbody = strHTMLbody & "<body>" & vbCrLf
strHTMLbody = strHTMLbody & "Username: " & Me!UserName & vbCrLf
strHTMLbody = strHTMLbody & "</body>" & vbCrLf
strHTMLbody = strHTMLbody & "</html>"


With objmailitem
.To = strManager
.Recipients.resolveall
.CC = myself
.Subject = "User Insurance Info"
.HTMLBody = True
.Body = strHTMLbody


.Display
End With

When I click send, the body of my Outlook email would look like this:
<html>
<head></head>
<body>
Username: <b>John Smith</b>
</body>
</html>

It seems like it does not recognize it as an HTML email.
Thanks.
 
Replace this:
.HTMLBody = True
.Body = strHTMLbody
with this:
.HTMLBody = strHTMLbody

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks PHV. It works!
And thanks to Huggyboy.
 
Thanks PHV - syntax differences between VBA & vb.net!!
If i recall correctly i had to convert from C# example (uses smtp rather than outlook)
 
Just an observation - you dont need the & vbCrLf in the html string - as far as i am aware they are ignored when the html is rendered.

All the formatting is done by the html tags so to create 2 empty lines lines before after user name (for instance)
strHTMLbody = strHTMLbody & "<br><br>Username: " & Me!UserName & "<br><br>".

I generally use a html editor with a preview facility to create the formatting then copy the html source as a string into my code (useful when using more advanced tags like table).
 
In my post stamped 25 Mar 09 11:27 I suggested the <p> flag.
 
Yes indeed - that would do the same thing.

My remarks were meant for snoopy80 to highlight the all unnecessary VbCrLf formatting in the html string.
eg "<html>" & vbCrLf etc.

H
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top