Open blank email from button

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • djgeverson
    New Member
    • Feb 2014
    • 10

    Open blank email from button

    Hi there,

    I want to have a button on an 'admin' form whereby the user of the database would click the button and a blank email would open in Outlook for the user to enter his/her problem into. But I want the 'to' email address and subject to be already present in the new email.

    If the Outlook program is closed, when the user clicks the button I also want Outlook to open and the blank email with subject and 'to' address filled in.


    I have the code below but when I click the button it, 1. doesnt open outlook and 2. sends the email without allowing someone to edit it.

    Can someone please help!!

    Code:
    Private Sub cmdemail_Click()
    
        Dim olApp As Object
        Dim objMail As Object
        
        On Error Resume Next 'Keep going if there is an error
        Set olApp = GetObject(, "Outlook.Application")  'this checks if outlook is open
        
            If Error Then 'if outlook is not open then do the following
                Set olApp = CreateObject("Outlook.Application")
            End If
            
        'creating the email item
        Set objMail = olApp.CreateItem(olMailItem)
        
        With objMail
        'then need to set the body the HTML format
            .BodyFormat = olFormatHTML
            .To = "david.everson@reemtsma.de"
            .Subject = "Product Development Ink and Varnish Database Help"
            .HTMLBody = "<htmltags>Thank you for your email. Please include a brief description of your problem below. I aim to respond to all problems within 3 working days</htmltags>"
            .send
        End With
        
    End Sub
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    The following should do the trick for you:
    Code:
    'Set a Reference to the Microsoft Outlook XX.X Object Library
    Dim oLook As Object
    Dim oMail As Object
     
    Set oLook = CreateObject("Outlook.Application")
    Set oMail = oLook.CreateItem(0)
     
    With oMail
     .To = "SomeBody@aol.com"
     .Subject = "Generic Subject"
       .Display
    End With
    
    Set oMail = Nothing
    Set oLook = Nothing

    Comment

    • djgeverson
      New Member
      • Feb 2014
      • 10

      #3
      Thats great! Thanks!

      Comment

      • ADezii
        Recognized Expert Expert
        • Apr 2006
        • 8834

        #4
        You are quite welcome.

        Comment

        Working...