Results 1 to 8 of 8
  1. #1
    NISMOJim is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Jul 2010
    Posts
    273

    Open Outlook & populate e-mail

    I've looked all over this forum and tried several different methods to do the same thing, but I can't get any of them to work for my application (most likely because I don't know what I'm doing). Here's what I would like to do;

    On my form is a checkbox option group. When I check the "Yes" box (build code in "Got Focus") I would like to open a new mail message using Outlook (preferably with the autosignature that shows up at the bottom when I normally click "New Mail Message", but that's not a deal-breaker).

    I need to send the message to Smith, John; Jones, Doug; and a name field from my form, Me.Supv (the names are from my work intranet, and that's how they normally show up in the "To:" box. I tried entering the full e-mail addresses in the code too, but nothing showed up in the "To:" box either way I tried).

    The subject should be another field from my form, Me.Type.

    The body of the e-mail is also from my form, Me.Sent1, Me.Sent2 & Me.Sent3.



    Lastly, I don't want the e-mail to be sent until the user manually clicks the "Send" button. They may need to add pictures as an attachment in some cases.

    I've just started learning VBA coding, and trying to understand how to apply other people's code to my situation is beyond me. I hope to learn enough so I don't have to keep bothering you guys, but that is still a bit in the future.
    Thank you for all of your help in the past, and again today.

  2. #2
    slave138's Avatar
    slave138 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Oct 2010
    Location
    WI
    Posts
    233
    I think this tutorial might be what you're looking for:
    http://www.blueclaw-db.com/access_em...nd_outlook.htm

  3. #3
    slave138's Avatar
    slave138 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Oct 2010
    Location
    WI
    Posts
    233
    The downside of sending emails from Outlook is that you will get a security prompt for each outgoing email. If you want to be able to send the message(s) without being prompted and have access to an SMTP server you can use the attached code.

  4. #4
    NISMOJim is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Jul 2010
    Posts
    273
    Thanks for helping me out. I tried this code earlier today, and just now copied & pasted it back in, but I'm getting the same error;

    Compile Error: User-Defined type not defined. The line that says appOutLook As Outlook.Application is hilighted in blue.

    This is really all Greek to me, so I have no idea how to fix it. Here's what it looks like;

    Private Sub ChkYEml_GotFocus()
    'Opens outlook & fills in message to send for notifications

    Dim mess_body As String
    Dim appOutLook As Outlook.Application
    Dim MailOutLook As Outlook.MailItem
    Set appOutLook = CreateObject("Outlook.Application")
    Set MailOutLook = appOutLook.CreateItem(olMailItem)
    Set appOutLook = CreateObject("Outlook.Application")
    Set MailOutLook = appOutLook.CreateItem(olMailItem)
    With MailOutLook
    .BodyFormat = olFormatRichText
    .To = Me.Email_Address
    .Subject = Me.SenTyp
    .HTMLBody = Me.Sent1
    '.DeleteAfterSubmit = True 'This would let Outlook send the note without storing it in your sent bin
    .Send
    End With
    'MsgBox MailOutLook.Body
    Exit Sub
    email_error:
    MsgBox "An error was encountered." & vbCrLf & "The error message is: " & Err.Description
    Resume Error_out
    Error_out:

    End Sub

    When this is working, can I get rid of the .Send line since I want the user to send it manually, and the If statement about the attachment since the user will do this manually also? I'll have more questions about the "To:" section later, but first things first.

    Thanks again.

  5. #5
    slave138's Avatar
    slave138 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Oct 2010
    Location
    WI
    Posts
    233
    You probably need to add a reference to the Outlook library. It looks like you're using Access 2003 so I assume you have the same version for Outlook.

    In the code editor window, go to Tools > References and select the Microsoft Outlook 11.0 Library.

    I'm not sure about the other questions you had because we send personalized messages to a large number of recipients which means all of my efforts have been focused on preventing users from having to send the messages manually. I tried one with the line commented out but nothing happened -- no message in the Outbox or anywhere else I could find. I'm not on an Exchange server at home so it might work differently in that enviornment.

  6. #6
    NISMOJim is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Jul 2010
    Posts
    273
    That may have done the trick. My Outlook is running real slow right now so I don't know for sure, but it is trying to send something to me (my trial e-mail address).
    So if I delete the .send line, will I be able to see the message before sending it so users can make changes if needed?
    You have been a lot of help tonight, but it's quittin' time for me now. I hope to find you again tomorrow to answer the rest of the questions I will have on this.
    Thanks again & have a great night.

  7. #7
    slave138's Avatar
    slave138 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Oct 2010
    Location
    WI
    Posts
    233
    The example on this site might be a better method for opening a new email (instead of just sending it):
    http://www.blueclaw-db.com/download/...ss_outlook.htm

    It uses the DoCmd.SendObject method instead of creating the Outlook.Application object. Another possibility would be to call a mailto link to open the message window. I don't know if the SendObject method limits body length but there are limits for mailto.

  8. #8
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    Jim,

    you might also want to look into 2007 or later. There are macro actions and such in those versions that simplify using Outlook almost down to nothing (task wise). With those, you probably wouldn't have to write code anymore to open the office objects.

    the other thing you might want to look at is this: http://www.access-programmers.co.uk/...hlight=outlook

    that is a WONDERFUL package. You can use just about any outgoing mail server you want, so you don't even have to mess with outlook. I've never seen anything more useful for Access than that.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Mail Merge
    By sakhtar in forum Access
    Replies: 8
    Last Post: 09-20-2020, 09:10 AM
  2. Replies: 16
    Last Post: 03-15-2010, 12:02 AM
  3. Replies: 2
    Last Post: 02-26-2010, 08:14 AM
  4. Mail Merge
    By Nixx1401 in forum Access
    Replies: 1
    Last Post: 02-15-2010, 10:51 AM
  5. E-mail Reports
    By Mike Cooper in forum Reports
    Replies: 2
    Last Post: 08-04-2008, 12:58 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