"Set MAPISession" getting error

Posted on 2009-07-08
Last Modified: 2013-11-27
I'm getting a error when trying to send out e-mail.  The error occurs on line below:
  Set MAPISession = CreateObject("MAPI.Session")
See code below for entire subroutine

Error Number: 429
Description: ActiveX component can't create object

This computer got screwed up with a faulty installation disk that remove a bunch of stuff.  I think my mapi stuff got removed.  How do I fix it?
Private Sub StartMessagingAndLogon()

    Dim sKeyName As String

    Dim sValueName As String

    Dim sDefaultUserProfile As String

    Dim osinfo As OSVERSIONINFO

    Dim retvalue As Integer


    On Error GoTo ErrorHandler

    Set MAPISession = CreateObject("MAPI.Session")


    'Try to log on.  If this fails, the most likely reason is

    'that you do not have an open session.  The error

    '-2147221231  MAPI_E_LOGON_FAILED returns.  Trap

    'the error in the ErrorHandler.

    MAPISession.Logon ShowDialog:=False, NewSession:=False

    Exit Sub


    Select Case Err.Number

       Case -2147221231  'MAPI_E_LOGON_FAILED

          'Need to determine what operating system is in use. The keys are different

          'for WinNT and Win95.

          osinfo.dwOSVersionInfoSize = 148

          osinfo.szCSDVersion = Space$(128)

          retvalue = GetVersionEx(osinfo)

          Select Case osinfo.dwPlatformId

             Case 0   'Unidentified

                LogEvt "Unidentified Operating System.  Cannot log on to messaging.", vbCritical, "Email Problem (ASO-3)"

                Exit Sub

             Case 1   'Win95

                sKeyName = "Software\Microsoft\" & _

                           "Windows Messaging " & _



             Case 2   'NT

                 sKeyName = "Software\Microsoft\Windows NT\" & _

                            "CurrentVersion\" & _

                            "Windows Messaging Subsystem\Profiles"

          End Select


          sValueName = "DefaultProfile"

          sDefaultUserProfile = QueryValue(sKeyName, sValueName)

          MAPISession.Logon ProfileName:=sDefaultUserProfile, _


          Exit Sub

       Case Else

          LogEvt "An error has occured while trying" & Chr(10) & _

          "to create and to log on to a new ActiveMessage session." & _

          Chr(10) & "Report the following error to your " & _

          "System Administrator." & Chr(10) & Chr(10) & _

          "Error Location: frmMain.StartMessagingAndLogon" & _

          Chr(10) & "Error Number: " & Err.Number & Chr(10) & _

          "Description: " & Err.Description, vbCritical, "Email Problem (ASO-4)"

    End Select

End Sub

Open in new window

Question by:schmir1
  • 4
  • 2
LVL 16

Expert Comment

by:Chuck Wood
ID: 24808553
Where do you define OSVERSIONINFO?

Author Comment

ID: 24814481
See below.  I can send you the entire module if that would help.

    dwOSVersionInfoSize As Long

    dwMajorVersion As Long

    dwMinorVersion As Long

    dwBuildNumber As Long

    dwPlatformId As Long

    szCSDVersion As String * 128

End Type

Open in new window


Author Comment

ID: 24882658
Anyone have any ideas?
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.


Author Comment

ID: 24910819
I guess I will close this question???
LVL 16

Accepted Solution

Chuck Wood earned 500 total points
ID: 24913741
I think you need to declare the MAPISession as an Object before you Set it.
    Dim MAPISession As Object

    On Error GoTo ErrorHandler

    Set MAPISession = CreateObject("MAPI.Session")

Open in new window


Author Comment

ID: 24956791
Thanks.  I'm running my code on my PC that works so I don't need to do your suggestion right way.  I'll assume it works.

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

707 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

12 Experts available now in Live!

Get 1:1 Help Now