Send basic email

bigalpha

Registered User.
Local time
Today, 05:47
Joined
Jun 22, 2012
Messages
415
I have set up a button that opens an Outlook email in which a report is PDF'd and attached.

Is it possible to populate the body of the email based on a text box from a form?

For example, I want the email to simply say, "Please review and comment on Work Order #1-111111", where the 1-111111 is populated from the form.
 
It would help to see your code, but in general you can build a body by concatenating fixed text with form references:

"Please review and comment on Work Order #" & Me.WorkOrderfield
 
Yes.

There are some limits to the length of .body hence the reference to "stored text" for standard signature etc.

Code:
Private Sub SendMail_Click()
Dim myOlApp As Object
Dim myEmail As Outlook.MailItem
Dim myBody3 As String

Set myOlApp = CreateObject("Outlook.Application")
Set myEmail = myOlApp.CreateItem(olMailItem)
myBody3 = "Dear " & Forms!customer.FirstName..... ETC

With myEmail
.To = Forms!customer.Email
.Subject = "Your full balance has been received"
.Body = myBody3 & Chr(13) & Chr(10) & Chr(13) & Chr(10) & DLookup("[text11]", "[storedtext]")

End With
myEmail.Display
Me!FULLACKBUTCLICK = Date
End Sub
 
It would help to see your code, but in general you can build a body by concatenating fixed text with form references:

"Please review and comment on Work Order #" & Me.WorkOrderfield

I don't have any code - I set up the mail function using the macro-builder.
 
I don't use macros, but you can try this in the body argument:

"Please review and comment on Work Order #" & Forms!FormName.WorkOrderfield

replacing the form and control names. I have a hunch it won't work though. If not, try SendObject in VBA code.
 
Yes.

There are some limits to the length of .body hence the reference to "stored text" for standard signature etc.

Code:
Private Sub SendMail_Click()
Dim myOlApp As Object
Dim myEmail As Outlook.MailItem
Dim myBody3 As String
 
Set myOlApp = CreateObject("Outlook.Application")
Set myEmail = myOlApp.CreateItem(olMailItem)
myBody3 = "Dear " & Forms!customer.FirstName..... ETC
 
With myEmail
.To = Forms!customer.Email
.Subject = "Your full balance has been received"
.Body = myBody3 & Chr(13) & Chr(10) & Chr(13) & Chr(10) & DLookup("[text11]", "[storedtext]")
 
End With
myEmail.Display
Me!FULLACKBUTCLICK = Date
End Sub

I tried to use this and received a "Compile Error, user type not defined" error on the first line.

My code
Code:
Private Sub btn_mail_report_Click()
Dim myOlApp As Object
Dim myEmail As Outlook.MailItem
Dim myBody3 As String
Set myOlApp = CreateObject("Outlook.Application")
Set myEmail = myOlApp.CreateItem(olMailItem)
myBody3 = "Work Order is due for review" & Forms!formPWO.PWONumber
With myEmail
.To = Forms!customer.Email
.Subject = "Please review the following Work Order"
.Body = myBody3 & Chr(13) & Chr(10) & Chr(13) & Chr(10) & DLookup("[text11]", "[storedtext]")
End With
myEmail.Display
Me!FULLACKBUTCLICK = Date
End Sub
 
That method mixes early and late binding, which I wouldn't recommend (I suspect your error is because Outlook isn't included in the references). I think you'll find SendObject simpler, though certainly automation (tallbloke's code) provides more flexibility.
 
Okay, I'll take a look at working with SendObject. I'll let you know if I create something that works or something that doesn't :D
 
Don't forget to change the names of my buttons etc!

So remove the DLookup and Me!FULLACKBUTCLICK = Date
 

Users who are viewing this thread

Back
Top Bottom