Results 1 to 4 of 4

Thread: MAPI Illegal operation

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2002
    Posts
    8

    MAPI Illegal operation

    Hi guys,

    I'm getting the error "This program has performed illegal operation error" when I access even a simple property of Mapi.session object. My deafault mail client is Outlook.

    eg. The following code displays the CurrentUser name but after dispaying it, VB gets closed by saying "This program has performed illegal operation"

    Private Sub Command1_Click()
    Dim oSession As Mapi.Session
    Set oSession = New Mapi.Session
    oSession.Logon "", "", False, False
    MsgBox oSession.CurrentUser
    Set oSession = Nothing
    End Sub

    Can anyone suggest me what to do ASAP?

    Thank you,
    Sandeep

  2. #2
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    Well

    Add

    VB Code:
    1. oSession.Close

    Before setting it = nothing...
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  3. #3

    Thread Starter
    New Member
    Join Date
    May 2002
    Posts
    8

    No close method

    Hi James,

    There's no method called close in the Session object. Instead I tried using oSessiojn.Logoff. But the problem still persists.

    Sandeep

  4. #4
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    Well

    Here's my email code that I use :

    VB Code:
    1. '*******************************************************************************
    2. ' SENDMESSAGETHRUOUTLOOK (SUB)
    3. '
    4. ' DESCRIPTION:
    5. ' ACTUALLY SEND THE EMAIL MESSAGE THRU OUTLOOK
    6. '*******************************************************************************
    7.  
    8. Sub SENDMESSAGETHRUOUTLOOK(DisplayMsg As Boolean, Optional AttachmentPath)
    9.    
    10.     Dim objOutlook As Outlook.Application
    11.     Dim objOutlookMsg As Outlook.MailItem
    12.     Dim objOutlookRecip As Outlook.Recipient
    13.     Dim objOutlookAttach As Outlook.Attachment
    14.    
    15.     ' CREATE THE OUTLOOK SESSION.
    16.    
    17.     Set objOutlook = CreateObject("Outlook.Application")
    18.    
    19.     ' CREATE THE MESSAGE.
    20.    
    21.     Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
    22.    
    23.     With objOutlookMsg
    24.        
    25.         ' ADD THE TO RECIPIENT(S) TO THE MESSAGE.
    26.        
    27.         Set objOutlookRecip = .Recipients.Add(Me.txtAddressTO.Text)
    28.        
    29.         objOutlookRecip.Type = olTo
    30.        
    31.         ' SET THE SUBJECT, BODY, AND IMPORTANCE OF THE MESSAGE.
    32.        
    33.         .Subject = Me.txtSubject.Text
    34.        
    35.         .HTMLBody = Me.txtMsg.Text
    36.        
    37.         .Importance = olImportanceHigh  ' HIGH IMPORTANCE
    38.        
    39.         ' ADD ATTACHMENTS TO THE MESSAGE.
    40.        
    41.         If Not IsMissing(AttachmentPath) Then
    42.            
    43.             Set objOutlookAttach = .Attachments.Add(Me.lblAttachment.Caption)
    44.            
    45.         End If
    46.        
    47.         ' RESOLVE EACH RECIPIENT'S NAME.
    48.        
    49.         For Each objOutlookRecip In .Recipients
    50.            
    51.             objOutlookRecip.Resolve
    52.            
    53.         Next
    54.        
    55.         ' SHOULD WE DISPLAY THE MESSAGE BEFORE SENDING?
    56.        
    57.         If DisplayMsg Then
    58.            
    59.             .Display
    60.            
    61.         Else
    62.            
    63.             .Save
    64.            
    65.             .Send
    66.            
    67.         End If
    68.        
    69.     End With
    70.    
    71.     Set objOutlook = Nothing
    72.    
    73. End Sub
    74.  
    75.  
    76.  
    77. '*******************************************************************************
    78. ' SENDMESSAGETHRUEXPRESS (SUB)
    79. '
    80. ' DESCRIPTION:
    81. ' ACTUALLY SEND THE EMAIL MESSAGE THRU EXPRESS
    82. '*******************************************************************************
    83.  
    84. Sub SENDMESSAGETHRUEXPRESS(DisplayMsg As Boolean, Optional AttachmentPath)
    85.    
    86.     MAPISession1.SignOn
    87.    
    88.     With Me.MAPIMessages1
    89.        
    90.         .SessionID = MAPISession1.SessionID
    91.        
    92.         .MsgIndex = -1
    93.        
    94.         .Compose
    95.        
    96.         .MsgSubject = Me.txtSubject
    97.        
    98.         .RecipType = mapToList
    99.        
    100.         .RecipDisplayName = Me.txtAddressTO
    101.        
    102.         .RecipAddress = Me.txtAddressTO
    103.        
    104.         ' SHOW THE ADDRESS BOOK WITH THE SELECTED RECIPIENT(S)
    105.        
    106.         ' 0=NO EDIT FIELDS, 1=TO, 2=(TO AND CC), 3=(TO, CC AND BLIND CC),
    107.         ' 4=ONLY THOSE SUPPORTED BY MESSAGING SYSTEM WILL BE SHOWN
    108.        
    109.         .AddressEditFieldCount = 1
    110.        
    111.         .MsgNoteText = Me.txtMsg
    112.        
    113.         ' ADD ATTACHMENT FILE IF THE LABEL CONTAINS A SELECTED FILE
    114.        
    115.         If Len(Me.lblAttachment.Caption) > 0 And Me.lblAttachment.Caption > " " Then
    116.            
    117.             .AttachmentPosition = 0
    118.            
    119.             .AttachmentName = lblAttachment
    120.            
    121.             .AttachmentPathName = lblAttachment
    122.            
    123.             .AttachmentType = mapEOLE
    124.            
    125.         End If
    126.        
    127.         ' SEND THE EMAIL
    128.        
    129.         .Send
    130.        
    131.     End With
    132.    
    133.     MAPISession1.SignOff
    134.    
    135. End Sub

    Feel free to change...
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width