Solved

MAPI Attachment Access

Posted on 1998-04-20
2
729 Views
Last Modified: 2010-05-18
I am trying to access information on a file attachment in Exchange using MAPI in VB 5.0.  This is explained quite well in the MS Knowledgebase but the code examples I find there do not work for me.  All the other MAPI examples seem to work fine when when I try to check any Attachment property I get a "run time error 438 - Object doesn't support this property or method" error.

I have tried it both using the MAPI on form controls and the  Set objSession = CreateObject("mapi.session") commands.

My code is:
  MapiSess.Action = 1
  If Err <> 0 Then
      MsgBox "Logon Failure: " + Error$
  Else
      MapiMess.SessionID = MapiSess.SessionID
  End If
  On Error GoTo 0
  MsgBox MapiMess(1).AttachmentCount 'This failes
  MapiMess(1).AttachmentIndex = 1 'This fails
  MsgBox MapiMess(1).AttachmentPathName 'This fails

I have also tried fetching the message first with no improvement.  My guess is that I'm not including some necessary reference or component but I can't figure out which.

I am referencing:
Microsoft MAPI Controls 5.0 (sp2)
Microsoft Active Messaging 1.1 object library

My conponents are:
Microsoft MAPI Controls 5.0 (sp2)

Any help is greatly appreciated.

Ken
0
Comment
Question by:kfenske
2 Comments
 
LVL 5

Accepted Solution

by:
bin_huwairib earned 100 total points
ID: 1425983
kfenske,
To access a file attachment using MAPI control, you must create a message set for all messages in the inbox (after establishing MAPI Session) by using Fetch method, and then you can access each message in that set with MsgIndex property and finally you can use AttachmentIndex property to access selected message attachment.

Example:
MapiSess.Action = 1
If Err <> 0 Then
 MsgBox "Logon Failure: " + Error$
Else
 MapiMess.SessionID = MapiSess.SessionID
 MapiMess.FetchUnreadOnly = False
 MapiMess.Fetch
 For I = 0 To MapiMess.MsgCount - 1
  MapiMess.MsgIndex = I
  MsgBox "From : " + MapiMess.MsgOrigDisplayName + vbCrLf + _
   "Attachment Count : " + Trim(MapiMess.AttachmentCount) + vbCrLf + _
   "Attachment Path : " + Trim(MapiMess.AttachmentPathName)
 Next
End If



0
 

Author Comment

by:kfenske
ID: 1425984
Excellent answer, this cleared it all up.

Ken
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

778 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