MS Access VBA Outlook Email Help

kevinh2320

Board Regular
Joined
May 13, 2016
Messages
61
I have a button on a form configured with an On Click event to run the code shown below. My question is on the .Subject and .Body lines of this code. Right now on the .Subject line I'm using the "Me" keyword declaring the field name "CustName" to display the customers name on the Subject line. This works just fine. However, what I can't figure out is a way to combine statically entered text and field names together. For example something that would display in the Subject line as: "Dear: John Smith". With the "Dear:" being statically entered text and "John Smith" being the dynamic field "Me.CustName". I wanting to accomplish combining text and field names in both the .Subject and .Body areas of the email.

Hope this make sense and appreciate any ideas on how to get this working.

Private Sub emailPayoffCongratsLtr_Click()

Dim objOutlook As Outlook.Application
Dim objEmail As Outlook.MailItem

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

'Generate email
With objEmail
.To = "kevin.husa@alaska.gov"
.Subject = Me.CustName
.Body = "Testing123"
.Display

End With

End Sub
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Hi Kevin,

Though this is an Excel forum is this what you're after:

VBA Code:
MsgBox "Dear: " & Me.CustName

Regards,

Robert
 
Upvote 0

Forum statistics

Threads
1,214,971
Messages
6,122,520
Members
449,088
Latest member
RandomExceller01

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top