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

Open outlook from Access to send mailto:

100+
P: 116
Please can anyone help.

I am trying to add a button to a form which will pick up an email address, launch outlook, place the address in "Sendto" field and then let me manually type a letter.

I have always used the code below but this only works for sending a message then closing outlook having sent an automated message. I need it to keep outlook open.

I am really a self taught novice at this and only found the code by chance and sure it will be easy for someone with knowledge.

Hope you can assist.

Regards
jacc14


Expand|Select|Wrap|Line Numbers
  1. Private Sub Command9_Click()
  2.  
  3. Dim bStarted As Boolean
  4. Dim oOutlookApp As Outlook.Application
  5. Dim oItem As Outlook.MailItem
  6.  
  7. On Error Resume Next
  8.  
  9.  
  10. 'Get Outlook if it's running
  11. Set oOutlookApp = GetObject(, "Outlook.Application")
  12. If Err <> 0 Then
  13.     'Outlook wasn't running, start it from code
  14.     Set oOutlookApp = CreateObject("Outlook.Application")
  15.     bStarted = True
  16. End If
  17.  
  18. 'Create a new mailitem
  19. Set oItem = oOutlookApp.CreateItem(olMailItem)
  20.  
  21. With oItem
  22.     'Set the recipient for the new email
  23.    .To = "jacc14@testing.co.uk"
  24.  
  25.     .Send
  26. End With
  27.  
  28. If bStarted Then
  29. '    'If we started Outlook from code, then close it
  30.     oOutlookApp.Quit
  31. End If
  32.  
  33. 'Clean up
  34. Set oItem = Nothing
  35. Set oOutlookApp = Nothing
  36.  
  37.  
  38.  
  39. End Sub
Jul 12 '07 #1
Share this Question
Share on Google+
5 Replies


FishVal
Expert 2.5K+
P: 2,653
Please can anyone help.

I am trying to add a button to a form which will pick up an email address, launch outlook, place the address in "Sendto" field and then let me manually type a letter.

I have always used the code below but this only works for sending a message then closing outlook having sent an automated message. I need it to keep outlook open.

I am really a self taught novice at this and only found the code by chance and sure it will be easy for someone with knowledge.

Hope you can assist.

Regards
jacc14


Expand|Select|Wrap|Line Numbers
  1. Private Sub Command9_Click()
  2.  
  3. Dim bStarted As Boolean
  4. Dim oOutlookApp As Outlook.Application
  5. Dim oItem As Outlook.MailItem
  6.  
  7. On Error Resume Next
  8.  
  9.  
  10. 'Get Outlook if it's running
  11. Set oOutlookApp = GetObject(, "Outlook.Application")
  12. If Err <> 0 Then
  13.     'Outlook wasn't running, start it from code
  14.     Set oOutlookApp = CreateObject("Outlook.Application")
  15.     bStarted = True
  16. End If
  17.  
  18. 'Create a new mailitem
  19. Set oItem = oOutlookApp.CreateItem(olMailItem)
  20.  
  21. With oItem
  22.     'Set the recipient for the new email
  23.    .To = "jacc14@testing.co.uk"
  24.  
  25.     .Send
  26. End With
  27.  
  28. If bStarted Then
  29. '    'If we started Outlook from code, then close it
  30.     oOutlookApp.Quit
  31. End If
  32.  
  33. 'Clean up
  34. Set oItem = Nothing
  35. Set oOutlookApp = Nothing
  36.  
  37.  
  38.  
  39. End Sub
Hi!

There is no need to write comprehensive code. Simply use
Expand|Select|Wrap|Line Numbers
  1.  FollowHyperlink "mailto:[mail address]"
Good luck.
Jul 13 '07 #2

100+
P: 116
Hi there.
Cant believe it. Just tried it and its so simple.

Many thanks

Jacc14
Jul 13 '07 #3

P: 7
FollowHyperlink "mailto:[mail address]"
Assuming [mail address] is the name of the control. My control name is ContactEmail. I changed it to this and it does not work for me. I have Access 2007. I get an error about communicating with the OLE server or Active X control.
Apr 7 '09 #4

Expert 100+
P: 1,287
Change
Expand|Select|Wrap|Line Numbers
  1. .Send
to
Expand|Select|Wrap|Line Numbers
  1. .Display
Apr 8 '09 #5

Expert 100+
P: 1,287
Or,
Expand|Select|Wrap|Line Numbers
  1. FollowHyperlink "mailto: " & [mail address]
Apr 8 '09 #6

Post your reply

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