Results 1 to 7 of 7
  1. #1
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Mapi Cancel (VB6)

    On creating a MAPI session, if the user decides to cancel mid way, does the MApi Session log it's self off automatically or is it still open even though the application isn't running.

    I've had a couple of situations where via code, a MAPI session is logged on and then the user decide to cancel without sending the mail.
    From there, the user has to reboot to enable them to use the code again ?
    Does the cancel button from the Mail Program(me) overide the session ?

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Mapi Cancel (VB6)

    What happens if the user cancels the Send method? Do you get an error message? If so, you should add error handling to all procedures that use a MapiSession control, and sign off in the exit part:

    Private Sub ...
    On Error GoTo ErrHandler
    MapiSession1.SignOn
    ...

    ExitHandler:
    MapiSession1.SignOff
    Exit Sub

    ErrHandler:
    MsgBox Err.Description, vbExclamation
    Resume ExitHandler
    End Sub

  3. #3
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Mapi Cancel (VB6)

    Hans, I don't get any errors but does this look correct:

    <pre>Private Sub procSendAll_Click(Index As Integer)
    On Error GoTo ErrHandler
    Dim i As Long
    Dim lngAttIndex As Long
    Dim intIndex As Integer

    lngAttIndex = 0

    If Me.lstEmail.ListCount = 0 Then
    MsgBox "No Items Selected For Mailing", vbInformation, "Information"
    Else
    'Logon & Sync
    MAPISession2.SignOn
    'Create Message w/Attachments then Send
    With MAPIMessages2
    .SessionID = MAPISession2.SessionID
    .Compose
    .MsgSubject = "Files From M&M Vehicle Repairs Ltd"
    .MsgNoteText = _
    Space(lstEmail.SelCount) & vbCrLf & _
    "Please Find Your Files As Attached" & vbCrLf & _
    "It May Be Necessary To Download Acrobat Reader" & vbCrLf & _
    "To View Estimates" & " " & "www.adobe.com"
    '================================================= ====
    For i = 0 To Me.lstEmail.ListCount - 1
    'Assign Index
    .AttachmentIndex = lngAttIndex
    .AttachmentPosition = lngAttIndex
    ' Increase index for next one
    lngAttIndex = lngAttIndex + 1
    .AttachmentPathName = Me.lstEmail.List(i)
    WriteLog GetComputerName & " " & GetNetUser & " Mail Sent " & " " & Me.lstEmail.List(i)
    Next i
    .Send True
    End With
    MAPISession2.SignOff
    Me.lstEmail.Clear

    End If
    exitHandler:
    MAPISession2.SignOff
    Exit Sub


    ErrHandler:
    If Err = 32002 Then
    WriteLog GetComputerName & " " & GetNetUser & " Mapi Error "
    MsgBox "An error occurred while trying to E:Mail...." & vbCrLf & _
    "This error occurs when your mail program is not the default" & vbCrLf & _
    "Mail Program.." & vbCrLf & _
    "Contact your IT support to have this enabled through" & vbCrLf & _
    "Internet Explorer or contact Dave Willett on" & vbCrLf & _
    "### ######...", vbCritical, "Mapi Error"
    End If
    Resume exitHandler
    End Sub</pre>


  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Mapi Cancel (VB6)

    It looks OK, and it is always useful to have error handling in your procedures, but I don't think it will help for this particular situation, if you don't get an error when cancelling the e-mail...

  5. #5
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Mapi Cancel (VB6)

    Hans Thanks.

    I've only come across this ExitHandler: over the last couple of days, and from what I can see proves to be useful.
    If I'm correct, it allows everything to be closed down correctly before exiting the sub even after an error.

    I suppose I should use this when using any of the ActiveX controls especially when they are using controls, ie Word or Outlook in the background.

    Should this be:

    <pre>exitHandler:
    MAPISession1.SignOff
    Me.lstDocs.Clear
    Unload Me
    End If
    ErrHandler:
    If Err = 32002 Then
    WriteLog GetComputerName & " " & GetNetUser & " Mapi Error "
    MsgBox "An error occured while trying to E:Mail...." & vbCrLf & _
    "This error occurs when your mail program is not the default" & vbCrLf & _
    "Mail Program.." & vbCrLf & _
    "Contact your IT support to have this enabled through" & vbCrLf & _
    "Internet Explorer or contact Dave Willett on" & vbCrLf & _
    "##### ######...", vbCritical, "Mapi Error"
    End If
    Resume exitHandler
    End Sub</pre>


    or

    <pre>exitHandler:
    MAPISession1.SignOff
    Me.lstDocs.Clear
    Unload Me
    End If
    ErrHandler:
    If Err = 32002 Then
    WriteLog GetComputerName & " " & GetNetUser & " Mapi Error "
    MsgBox "An error occured while trying to E:Mail...." & vbCrLf & _
    "This error occurs when your mail program is not the default" & vbCrLf & _
    "Mail Program.." & vbCrLf & _
    "Contact your IT support to have this enabled through" & vbCrLf & _
    "Internet Explorer or contact Dave Willett on" & vbCrLf & _
    "##### ######...", vbCritical, "Mapi Error"
    Resume exitHandler
    End If
    End Sub</pre>


    Will version 1 go into a continuous loop ?

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Mapi Cancel (VB6)

    You should use version 1, for then the clean-up routine will ALWAYS be executed. If you're afraid that this part will cause an error again, you can insert

    On Error Resume Next

    immediately below the ExitHandler: label. By the way, I would put the End If before the ExitHandler: label.

  7. #7
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Mapi Cancel (VB6)

    Hans
    Thanks for the advice, I have implemented all changes.

    Dave

Posting Permissions

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