Results 1 to 5 of 5
  1. #1
    NateSmith is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2013
    Posts
    6

    Outlook Email not being Displayed on Click - Please Help!

    Hi Everyone. I am having a tough time getting an outlook email to display after I click the button. Can someone please take a look at the code below? I am getting an error message that says, "user defined typed not defined" when I get to the line that says, "Dim olApp As Outlook.Application"

    -------------------------------------

    Private Sub Command13_Click()

    'Email code starts here
    'Reference the Outlook Application
    Dim olApp As Outlook.Application

    'The NameSpace object allows you to erference folders
    Dim olNS As Outlook.NameSpace
    Dim olFolder As Outlook.MAPIFolder

    'Create a reference to the mail item you will use to send your email
    Dim olMailItem As Outlook.MailItem

    'Create the Outlook object
    Set olApp = CreateObject("Outlook.Application")
    Set olNS = olApp.GetNamespace("MAPI")


    Set olFolder = olNS.GetDefaultFolder(olFolderInbox)
    Set olMailItem = olFolder.Items.Add("IPM.Note")

    'Create the body of the message
    strBodyText = "Testing Email Function"

    'Update the new mail object with your data
    .Subject = "Email Test"
    .To = email@email.com
    .CC = email@email.com
    .Body = strBodyText
    .Display

    End With

    'Release all of your object variables
    Set olMailItem = Nothing
    Set olFolder = Nothing
    Set olNS = Nothing
    Set olApp = Nothing
    End Sub

    -------------------------------------------------------------------------
    Thanks to anyone who can help me out on this

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Have you selected VBA reference Microsoft Outlook 14.0 Object Library
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    What exactly are you trying to do? Are you just trying to send an email? Why are you using this line?
    Set olMailItem = olFolder.Items.Add("IPM.Note")

  4. #4
    NateSmith is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2013
    Posts
    6
    Thank you both for your help. I appreciate the time you have taken to answer my question.

    June7, not sure if I did this or not. I will look into it. To be honest, I don't know much about VBA. I have used VBA for an email before, so I just copied and pasted what I had from that Access form code. Then again, I don't remember doing this for the last form I made.

    ItsMe, I am trying to click a button and have it send an email. I will also have it loop through a dataset to find which record values are present, but before I do this, I just want to make sure I have the email portion down. I am using this line: Set olMailItem = olFolder.Items.Add("IPM.Note") because I used this line of code when I had a similar task. Should I get rid of it? Would this returnme the aforementioned error message?

  5. #5
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    You are getting the error because of what June mentioned. In order to make that declaration you need to have a reference to the library. Another option is to generically declare it as an object and then bind the object later.

    Here is an example of using "Late Binding" to send an email.
    https://www.accessforums.net/program...tml#post209058

    Another option to send an email using Docmd. Here is an example of attaching a PDF based on a report.
    https://www.accessforums.net/forms/m...tml#post199193
    There are other examples of using this method nested within a DAO loop.

    Here is another example of creating an Outlook instance. This example uses "Early Binding" and requires you to include the reference (from within the VBA editor go to Tools>References) that June mentioned earlier. In other words, the declarations of the objects (Outlook objects) requires the reference to the Outlook Object library.
    https://www.accessforums.net/access/...tml#post196395
    I was looking at this example and noticed that strWhere does not get set. Not a big deal but would have to be addressed in order for it not to error.

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

Similar Threads

  1. Outlook batch email PDF
    By Ruegen in forum Reports
    Replies: 43
    Last Post: 12-12-2013, 10:55 PM
  2. Replies: 4
    Last Post: 03-06-2013, 04:59 AM
  3. Replies: 1
    Last Post: 03-15-2012, 05:41 PM
  4. Email and Outlook
    By Douglas Post in forum Programming
    Replies: 1
    Last Post: 02-13-2012, 02:57 PM
  5. Query displayed as body of email - edit
    By virnier in forum Access
    Replies: 0
    Last Post: 03-16-2011, 01:26 PM

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