A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Why doesn't this code work?



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old August 7th 06, 07:03 PM posted to microsoft.public.outlook.program_vba
Dale
external usenet poster
 
Posts: 15
Default Why doesn't this code work?

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




Ads
  #2  
Old August 7th 06, 09:03 PM posted to microsoft.public.outlook.program_vba
Dmitry Streblechenko
external usenet poster
 
Posts: 2,116
Default Why doesn't this code work?

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

"Dale" D-Man wrote in message
...
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






  #3  
Old August 7th 06, 09:14 PM posted to microsoft.public.outlook.program_vba
Dale
external usenet poster
 
Posts: 15
Default Why doesn't this code work?

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



"Dmitry Streblechenko" wrote in message
...
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

"Dale" D-Man wrote in message
...
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








 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
add 1+XXX area code to phone nr in my area code OH Outlook - Using Contacts 3 August 3rd 06 04:45 PM
how to make this code work pierre Outlook and VBA 2 June 15th 06 02:16 PM
transfer of zip code to word with mail merge doesn't work Ken Outlook - Using Contacts 1 April 25th 06 09:48 PM
code : Code : 800cccd2 scotty971fr Outlook Express 1 January 20th 06 12:59 AM
Saving as a Template means code doesn't work Michael Anderson Outlook - Using Forms 1 January 19th 06 06:22 PM


All times are GMT +1. The time now is 08:25 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.