I have a table called ClientListtbl and a form called ClientListfrm. on the form there is a click button to automatically generate an email. please see code below
Private Sub Command20_Click()
Dim LastName As Variant
Dim Email As Variant
Dim Notes As Variant
Dim Insurer As Variant
Dim Premium As Variant
Dim RenewalDate As Date
Dim objOutlook As Object
Dim objEmail As Object
LastName = Forms("ClientListfrm").LastName
Email = Forms("ClientListfrm").EmailAddress
Notes = Forms("ClientListfrm").Notes
Insurer = Forms("ClientListfrm").Insurer
Premium = Forms("ClientListfrm").Premium
Set objOutlook = CreateObject("Outlook.Application")
Set objEmail = objOutlook.CreateItem(0)
With objEmail
.To = Email
.Subject = "transfer " & LastName & " from James"
.HTMLBody = Insurer & _
Premium & _
RenewalDate & _
Notes
.Send
End With
Set objEmail = Nothing
Set objOutlook = Nothing
End Sub
I'd like the email to not send automatically so it can be reviewed by the user before sending, but I can't seem to figure how to change that.
And in the HTMLBody, i'd like there to be a new line for each field but all the examples I've seen and tried don't work.
And the RenewalDate in the HTMLBody displays in the email as 20000:00:00 and not the date shown on the form.
Thank you in advance for any help you can provide.
CodePudding user response:
Use .Display
instead of .Send
.
If you want to send HTML, you need to build HTML. E.g.
.HTMLBody = "<p>" & Insurer & "</p>" & _
"<p>" & Premium & "</p>"
etc. Or build your string with vbCrLf
separators, and then use HtmlEncode()
on the result.
You don't set RenewalDate
in your code. Use the Format()
function, if necessary.