Error 13 (type mismatch)  when sending emails from access

Posted on 2012-09-20
Last Modified: 2012-09-20

I'm getting error 13 (type mismatch) when attempting to send emails from within Access 2003.

My code (which works for other clients) is:

Global OutlookApplication As Outlook.Application, OutlookMail As Outlook.MailItem, Inbox As Outlook.MAPIFolder, DetailSectionLeftDescriptionLabel As String

Set OutlookApplication = New Outlook.Application
Set OutlookMail = Outlook.Application.CreateItem(olMailItem)

I get error 13 with the last line.  The Client has Access 2003 and Office 2010 on a 32bit Win 7 PC.  The project has a reference for Microsoft  Outlook 14.0 Object Library added and I have tried moving it up the reference list as far as it can go.

Any help would be appreciated

Question by:WSIT
    LVL 61

    Expert Comment

    No obvious type mismatch issue jumping out at me, but try changing the last line to reference the outlook application object that your code created in the previous statement:

    Set OutlookMail = OutlookApplication.CreateItem(olMailItem)

    (I've dropped the 'dot' in Outlook.Application)
    LVL 61

    Expert Comment

    Also, just for kicks - If you don't have it already, place the following line at the top of this code module, right under Option CompareDatabase:

    Option Explicit

    Open in new window

    Then compile your code, fixing any errors to ensure that all variables, Outlook constants, etc are recognized on your client's computer.
    LVL 61

    Accepted Solution

    One more suggestion (involving a code change) - you can eliminate problems with product versions by using 'Late Binding'.  This involves declaring things as generic Objects instead of application specific types such as Outlook.Application, Outlook.MailItem, etc.

    It's explained here:

    The examples in the articles are Excel and Word automation, but the same principle applies to Outlook, Word or anything else.

    Your code, using Late Binding would look something like this:

    Global OutlookApplication As Object, OutlookMail As Object, Inbox As Object, DetailSectionLeftDescriptionLabel As String
    Set OutlookApplication = CreateObject("Outlook.Application")
    Set OutlookMail = OutlookApplication.CreateItem(0)  '<-- replaced olMailItem with the actual value

    Open in new window


    Author Closing Comment

    I in the process of testing your ideas when I got a call to say they 'repaired' the Office installation and it then worked fine.  Why it would need repairing on all three PCs I couldn't tell you.  But thanks for the help.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
    A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
    Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
    In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now