Solved

MAPI Attachment Access

Posted on 1998-04-20
2
732 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

733 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