Add value from field in a form into .HTMLbody of an email

diarmaidbrown

New member
Local time
Today, 23:45
Joined
Jul 8, 2011
Messages
8
Hey all im im using a button in a form to automaticallly send an email to the email address in the form and use the Name in the subject. Im using outlook and the.BodyFormat = olFormatHTML the problem ive having is referencing the Booking number and Date from the Form in the HTML body. Any help would be great

thanks in advance
 
I assume your code builds a string. Typically you'd do this type of thing:

VariableName = "Dear " & Me.PersonsName & " your order number is " & Me.BookingNumber & " and so on"

In an HTML body, you add line breaks with <br>
 
Im using the following code

Option Compare Database

Private Sub Command27_Click()


Dim mess_body As String
Dim appOutLook As Outlook.Application
Dim MailOutLook As Outlook.MailItem
Dim StMailBody As String
Set appOutLook = CreateObject("Outlook.Application")
Set MailOutLook = appOutLook.CreateItem(olMailItem)


StMailBody = "Please ensure that the details below are correct." < br > "Booking Ref Number:" & BSN < br > "Name:" & Me.Name < br > " Date and time of booking: " & Me.DateofBooking & Me.TimeofBooking

Set appOutLook = CreateObject("Outlook.Application")
Set MailOutLook = appOutLook.CreateItem(olMailItem)
With MailOutLook
.BodyFormat = olFormatHTML
.To = Me.EmailAddress
.Subject = "Hi"
.HTMLBody = StMailBody


.Send
End With

Exit Sub
email_error:
MsgBox "An error was encountered." & vbCrLf & "The error message is: " & Err.Description
Resume Error_out
Error_out:


End Sub


The Email sends but the body just reads False is there any way that i can just write it in plaintxt and use & Chr$(13) & _ to take a new line?
 
Try:

Code:
StMailBody = "<html><body>Please ensure that the details below are correct. <br/> Booking Ref Number:" & BSN & "<br/> Name:" & Me.Name & "<br/> Date and time of booking: " & Me.DateofBooking & " " & Me.TimeofBooking

I would recommend you look at how html is constructed here.

hth
Chris
 
Sorry, to answer your question, if you want to use plain text then:

Code:
StMailBody = "Please ensure that the details below are correct." & vbCrLf & "Booking Ref Number:" & BSN & vbCrLf & "Name:" & Me.Name & vbCrLf & "Date and time of booking: " & Me.DateofBooking & " " & Me.TimeofBooking

and change .HTMLbody to .body

Also remove the .bodyformat line

hth
Chris
 
Thanks helped lot and cheers for the learning resource think ill just go for plain txt for now and have a go at playin around and get a understanding of html to format the txt at later date

thanks again
 
To use HTML body you'd put the <br> inside the quotes, not outside.
 

Users who are viewing this thread

Back
Top Bottom