By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,695 Members | 1,597 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,695 IT Pros & Developers. It's quick & easy.

Open blank email from button

P: 10
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!!

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdemail_Click()
  3.     Dim olApp As Object
  4.     Dim objMail As Object
  6.     On Error Resume Next 'Keep going if there is an error
  7.     Set olApp = GetObject(, "Outlook.Application")  'this checks if outlook is open
  9.         If Error Then 'if outlook is not open then do the following
  10.             Set olApp = CreateObject("Outlook.Application")
  11.         End If
  13.     'creating the email item
  14.     Set objMail = olApp.CreateItem(olMailItem)
  16.     With objMail
  17.     'then need to set the body the HTML format
  18.         .BodyFormat = olFormatHTML
  19.         .To = ""
  20.         .Subject = "Product Development Ink and Varnish Database Help"
  21.         .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>"
  22.         .send
  23.     End With
  25. End Sub
Feb 14 '14 #1
Share this Question
Share on Google+
3 Replies

Expert 5K+
P: 8,704
The following should do the trick for you:
Expand|Select|Wrap|Line Numbers
  1. 'Set a Reference to the Microsoft Outlook XX.X Object Library
  2. Dim oLook As Object
  3. Dim oMail As Object
  5. Set oLook = CreateObject("Outlook.Application")
  6. Set oMail = oLook.CreateItem(0)
  8. With oMail
  9.  .To = ""
  10.  .Subject = "Generic Subject"
  11.    .Display
  12. End With
  14. Set oMail = Nothing
  15. Set oLook = Nothing
Feb 14 '14 #2

P: 10
Thats great! Thanks!
Feb 21 '14 #3

Expert 5K+
P: 8,704
You are quite welcome.
Feb 21 '14 #4

Post your reply

Sign in to post your reply or Sign up for a free account.