Why doesn't this code work?

D

Dale

Hello all,

I posted the folloing in Access modules newsgroup and received a suggestion
to post it in an Outlook newsgroup. Well, here goes.


I'm trying to write code in an Access module which is working with Outlook
email messages. It works fine on my machine. If I save it to the network
and then have him save it to his desktop to do testing, I get a "Type
Mismatch error". Here is the code. I'm not sure but I think
oFldr.Items.COUNT might have something to do with it because of the way
COUNT is in all caps.

Option Compare Database

Public Sub ProcessInbox()
Dim rs As New ADODB.Recordset
Dim strSQL As String
Dim oOutlook As Outlook.Application
Dim oNs As Outlook.NameSpace
Dim oFldr As Outlook.MAPIFolder
Dim oAttachments As Outlook.Attachments
Dim oAttachment As Outlook.Attachment
Dim iMsgCount As Integer
Dim oMessage As Outlook.MailItem
Dim SubFolder As Outlook.MAPIFolder
Dim iCtr As Long, iAttachCnt As Long
Dim sFileNames As String
Dim aFileNames() As String
Dim ConcatenatedFilename As String
Dim SenderString As String
Dim foundClientName As String

'get reference to inbox
Set oOutlook = New Outlook.Application
Set oNs = oOutlook.GetNamespace("MAPI")
Set oFldr = oNs.GetDefaultFolder(olFolderInbox)
Set SubFolder = oFldr.Folders("Efiles")

'Debug.Print "Total Items: "; oFldr.Items.Count
'Debug.Print "Total Unread items = " & oFldr.UnReadItemCount

MsgBox "Total Items: " & oFldr.Items.COUNT
MsgBox "Total Unread items = " & oFldr.UnReadItemCount

SenderString = "Sean LauterbachDale JonesJoe HoemeJohn HanzelRob HanksKeith
SchwartingDave ByrneAmy KalsowEd SorensenTom Bush"

For Each oMessage In oFldr.Items --------------------------THE ERROR
OCCURS HERE---------------!!!!!!!!!!!!!

With oMessage

'basic info about message
Debug.Print .To
Debug.Print .CC
Debug.Print .Subject
Debug.Print .Body


Hope someone can help.

Regards Dale
 
D

Dmitry Streblechenko

You dimmed oMessage as Outlook.MailItem, but the Inbox folder can contain
items other than MailItem, e.g. meetifn requests, NDRs, etc.
Declare oMessage as a generic Object and check that the oMessage.Class
property = 43 before proceeding with a code that assumes that you are
workign with Outlook.MailItem.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
D

Dale

Hello Dmitry,

Thanx for the response.

I was kinda working my way around to that realization (the object issue)
when I got your message. I had found code which seemed to allude to that
fact. However, my attempt to put it in place seemd to fail with the exact
same error. I'll try your suggestion and hope it corrects the problem.

Regards
Dale
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top