Click to See Complete Forum and Search --> : MAPI Illegal operation
sandeep_id
Sep 4th, 2002, 08:27 AM
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
James Stanich
Sep 4th, 2002, 09:16 PM
Add
oSession.Close
Before setting it = nothing...
sandeep_id
Sep 4th, 2002, 09:52 PM
Hi James,
There's no method called close in the Session object. Instead I tried using oSessiojn.Logoff. But the problem still persists.
Sandeep
James Stanich
Sep 4th, 2002, 10:00 PM
Here's my email code that I use :
'*******************************************************************************
' SENDMESSAGETHRUOUTLOOK (SUB)
'
' DESCRIPTION:
' ACTUALLY SEND THE EMAIL MESSAGE THRU OUTLOOK
'*******************************************************************************
Sub SENDMESSAGETHRUOUTLOOK(DisplayMsg As Boolean, Optional AttachmentPath)
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment
' CREATE THE OUTLOOK SESSION.
Set objOutlook = CreateObject("Outlook.Application")
' CREATE THE MESSAGE.
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
With objOutlookMsg
' ADD THE TO RECIPIENT(S) TO THE MESSAGE.
Set objOutlookRecip = .Recipients.Add(Me.txtAddressTO.Text)
objOutlookRecip.Type = olTo
' SET THE SUBJECT, BODY, AND IMPORTANCE OF THE MESSAGE.
.Subject = Me.txtSubject.Text
.HTMLBody = Me.txtMsg.Text
.Importance = olImportanceHigh ' HIGH IMPORTANCE
' ADD ATTACHMENTS TO THE MESSAGE.
If Not IsMissing(AttachmentPath) Then
Set objOutlookAttach = .Attachments.Add(Me.lblAttachment.Caption)
End If
' RESOLVE EACH RECIPIENT'S NAME.
For Each objOutlookRecip In .Recipients
objOutlookRecip.Resolve
Next
' SHOULD WE DISPLAY THE MESSAGE BEFORE SENDING?
If DisplayMsg Then
.Display
Else
.Save
.Send
End If
End With
Set objOutlook = Nothing
End Sub
'*******************************************************************************
' SENDMESSAGETHRUEXPRESS (SUB)
'
' DESCRIPTION:
' ACTUALLY SEND THE EMAIL MESSAGE THRU EXPRESS
'*******************************************************************************
Sub SENDMESSAGETHRUEXPRESS(DisplayMsg As Boolean, Optional AttachmentPath)
MAPISession1.SignOn
With Me.MAPIMessages1
.SessionID = MAPISession1.SessionID
.MsgIndex = -1
.Compose
.MsgSubject = Me.txtSubject
.RecipType = mapToList
.RecipDisplayName = Me.txtAddressTO
.RecipAddress = Me.txtAddressTO
' SHOW THE ADDRESS BOOK WITH THE SELECTED RECIPIENT(S)
' 0=NO EDIT FIELDS, 1=TO, 2=(TO AND CC), 3=(TO, CC AND BLIND CC),
' 4=ONLY THOSE SUPPORTED BY MESSAGING SYSTEM WILL BE SHOWN
.AddressEditFieldCount = 1
.MsgNoteText = Me.txtMsg
' ADD ATTACHMENT FILE IF THE LABEL CONTAINS A SELECTED FILE
If Len(Me.lblAttachment.Caption) > 0 And Me.lblAttachment.Caption > " " Then
.AttachmentPosition = 0
.AttachmentName = lblAttachment
.AttachmentPathName = lblAttachment
.AttachmentType = mapEOLE
End If
' SEND THE EMAIL
.Send
End With
MAPISession1.SignOff
End Sub
Feel free to change...;)
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.