Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    dfean is offline Novice
    Windows 10 Access 2010 64bit
    Join Date
    Jul 2016
    Posts
    14

    How to use Access to create a button that opens an Outlook Email?

    Hi,



    In Access, I want to basically make a button that when you click on it would Outlook email saying,

    To: (the person email address)
    Subject: Request a laptop
    Body: I would Like to request a laptop please.
    -----------------------
    And then you can send this email

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    Not sure if you need to edit the email before sending or you want full automation. Here is some code to get you started.

    Code:
    'Reference Microsoft Outlook and
    'use early binding
    Dim objOutlook As New Outlook.Application
    Dim objNewEmail As MailItem
    'Dim objAttachReport As Attachments
    ''Instantiate your objects
    Set objNewEmail = objOutlook.CreateItem(olMailItem)
    'Set objAttachReport = objNewEmail.Attachments
    ''Add your file to the Attachments Collection
    'objAttachReport.Add "C:\Test\PDF_Files\Test.pdf", olByValue
        With objNewEmail
            .BodyFormat = olFormatRichText
            .To = "myEmail@email.com"
            .Subject = "Test Message"
            .HTMLBody = "This is the body of the message"
    '        'Save the email to ensure the attachment is a
    '        'copy of the original file (olByValue)
    '        .Save
    '        .Send
        End With
    
    'tidy up
    Set objAttachReport = Nothing
    Set objNewEmail = Nothing
    Set objOutlook = Nothing
    
    MsgBox "Complete"
    Last edited by ItsMe; 08-13-2016 at 11:01 AM.

  3. #3
    dfean is offline Novice
    Windows 10 Access 2010 64bit
    Join Date
    Jul 2016
    Posts
    14
    Would I have to create a macro or something else.

  4. #4
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    I am not sure what you mean by, "macro". Access has tools that can help you do stuff, like create emails, interact with Outlook, etc. Access has predefined actions that you can automate by creating an Access Macro.

    What I have provided here is VBA code. This can reside in a Form's Module, for example. I typically use forms and VBA code to do stuff.

  5. #5
    dfean is offline Novice
    Windows 10 Access 2010 64bit
    Join Date
    Jul 2016
    Posts
    14
    How do you link that module to the command button?

  6. #6
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    When you create a form, there is not a Module associated with the form. So you can add a Command Button via the Ribbon, under the design tab. It seems you know how to do this. The trick to VBA is not to use the Wizard that will launch by default. Newer versions of Access use the Wizard to create Macro's, embedded Macros to be more precise. These Macros are not VBA.

    Work in your form via Design View for best results.

    To add VBA code to a Command Button, add the button to the design surface, cancel the wizard if it launches and use the ellipses next to the desired Event that is described in the Command Button's properties window.

    Under the Event tab in the properties window, you will see a click event for Command Buttons. Make sure your Command Button has focus while you are looking at the properties window. Otherwise, you will be adjusting the properties for another control and or Object. When you click the elapses (...) a couple of dialog buttons will pop-up. I can't remember what they ask, but you want to create VBA code. You want to create a new event and do not want to use the wizard or create a Macro.

    Here is a screenshot of the property window.

    Click image for larger version. 

Name:	PropertyWindow.jpg 
Views:	15 
Size:	66.0 KB 
ID:	25438

    You do not want to create an embedded macro.
    Click image for larger version. 

Name:	EmbededMacro.jpg 
Views:	15 
Size:	48.0 KB 
ID:	25439

  7. #7
    dfean is offline Novice
    Windows 10 Access 2010 64bit
    Join Date
    Jul 2016
    Posts
    14
    Something went wrong,

    Click image for larger version. 

Name:	hekll.JPG 
Views:	15 
Size:	82.4 KB 
ID:	25440

  8. #8
    dfean is offline Novice
    Windows 10 Access 2010 64bit
    Join Date
    Jul 2016
    Posts
    14
    Okay I have started again

    Do I click on Code Bulider or Expression Builder
    Click image for larger version. 

Name:	Capture.JPG 
Views:	15 
Size:	91.6 KB 
ID:	25441

  9. #9
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    You want Code Builder

  10. #10
    dfean is offline Novice
    Windows 10 Access 2010 64bit
    Join Date
    Jul 2016
    Posts
    14
    Okay I did that then I typed the code in,

    Click image for larger version. 

Name:	Capture1.JPG 
Views:	15 
Size:	137.4 KB 
ID:	25442

    Then what do I do next do I save it, or something.

  11. #11
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    OK pretty good. When you clicked the ellipses and followed the dialog windows, you launched the VBA editor and created a module that will always be associated with your form.

    In addition, because you launched the VBA editor via the ellipses, you created an event handler within your new VBA module. In other words, Access added the first and last line of code for your "Click Event". The first line is "Private Sub Command0_Click" and the last line of code for your event handler is "End Sub".

    All of your code, all of your statements that you want executed when the event handles a click, belongs after the first line of code and before the last (End Sub).

  12. #12
    dfean is offline Novice
    Windows 10 Access 2010 64bit
    Join Date
    Jul 2016
    Posts
    14
    Could you show me screenshots of how to do it possibly please, I'm kinda new to all of this.
    Thanks

  13. #13
    dfean is offline Novice
    Windows 10 Access 2010 64bit
    Join Date
    Jul 2016
    Posts
    14
    Because this happened

    Click image for larger version. 

Name:	Capture2.JPG 
Views:	15 
Size:	85.3 KB 
ID:	25443

  14. #14
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    Not a problem, give me a minute.

    Meanwhile, see if you can find the correct reference needed. Using the VBA editor, from the menu bar at the top, under tools, select References. The References window will open. You want to select your version of Microsoft Outlook from the list of optional references. In this screenshot, you will see I have selected Microsoft Outlook 15.0 Object Library. Mine is 15.0 because of the version of Outlook I am using.

    Click image for larger version. 

Name:	ReferenceOutlook.jpg 
Views:	15 
Size:	176.0 KB 
ID:	25448

  15. #15
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    Here is a sample DB that will use Outlook to start an email.
    Attached Files Attached Files

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 5
    Last Post: 11-24-2015, 04:31 PM
  2. can I create/update an Outlook email group from my Access data?
    By jimdharris in forum Import/Export Data
    Replies: 2
    Last Post: 08-31-2015, 10:07 AM
  3. Replies: 5
    Last Post: 05-07-2014, 09:25 AM
  4. email address field opens in Outlook?
    By pbouk in forum Forms
    Replies: 1
    Last Post: 06-04-2013, 03:29 PM
  5. Replies: 2
    Last Post: 09-11-2011, 05:19 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums