Email via Outlook from a Command Button

Oshoryu

New Member
Joined
Apr 5, 2014
Messages
9
Hi,

I want to add a button on form which the user can press and a blank email will be displayed for the user to add a couple of bits of info and then send it.

The Address and the subject are already filled out.

I've worked out how to open the mail from the button and populate the To: and Subject: fields with the code, but when it comes to the body I want to have say three Headers that the user can fill relevent info.

Here is my code so far:

Code:
Private Sub Command14_Click()
DoCmd.SendObject _
    , _
    , _
    , _
    "[EMAIL="emailaddress@company.com"]emailaddress@company.com[/EMAIL]", _
    , _
    , _
    "Email Subject Text", _
    "Company Name:", _
    True

End Sub

As you can see "Company Name" is in the main body of the email, but I want to add some more data like, Name: Position: etc but on different lines, it's amazing how much you take the Enter button for a new line for granted!

Also, if the email is sent, it works fine, if the user cancels the email, Access freaks a bit, I'm sure I'm missing a bit of code here too.

Many thanks
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Hello Oshoryu,

You'll need to tweak the following code a bit to get it where you want it, but this should be a solid starting point:

Code:
Private Sub Command14_Click()
    
Dim OutApp As Object
Dim OutMail As Object
    
    Set OutApp = CreateObject("Outlook.Application")
    OutApp.Session.Logon
    Set OutMail = OutApp.CreateItem(0)
    
    With OutMail
        .To = "Update with email addresses"
        .CC = ""
        .BCC = ""
        .Subject = ""
        .Body = "Company Name:" & vbNewLine & "Position:" & vbNewLine & "etc:" & vbNewLine 'continue doing this for additional data
        .Display   'use .Display or .Send
    End With
       
    Set OutMail = Nothing
    Set OutApp = Nothing


End Sub

Thanks,
Thomas
 
Last edited:
Upvote 0

Forum statistics

Threads
1,221,869
Messages
6,162,530
Members
451,773
Latest member
ssmith04

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