Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Works with Outlook 2002 but not 2003 1

Status
Not open for further replies.

PortyAL

Technical User
May 13, 2005
126
GB
Hi

I have a machine running Outlook 2002 and Access 2002. The code below searches a subfolder in my inbox called "Temp", finds any messages flagged as "complete", displays the emails and saves them as HTML files to a folder as specified in the field "docfolder" in the open Access form "form1".

The Access project has Microsoft Outlook 10.0 Object Library installed.

The code works perfectly, but problems have arisen when I tried to use it on a machine with Outlook 2003 installed. The Access version is still 2002 but the project has Microsoft Outlook 11.0 Library installed rather than 10.0.

I get an "Object doesn't support this property or method" error on the line If temp.Items.Item(i).FlagStatus = olFlagComplete Then below.

Any help would be greatly appreciated.

Code:
Sub Analyze_Email()
   Dim ns As Outlook.NameSpace
   Dim sent As Outlook.MAPIFolder
   Dim temp As Outlook.MAPIFolder
   Dim i As Integer

   
   Set ns = GetNamespace("MAPI")
 
   ' Temp is a subfolder of Inbox
   Set temp = ns.GetDefaultFolder(olFolderInbox).Folders("Temp")
   
   For i = temp.Items.Count To 1 Step -1
   If temp.Items.Item(i).FlagStatus = olFlagComplete Then
        temp.Items.Item(i).Display
        temp.Items.Item(i).SaveAs forms!form1!docfolder & "\" & temp.Items.Item(i).Subject & ".htm", olHTML
        
      End If
   Next
   
     
   Set temp = Nothing
   Set ns = Nothing
End Sub

Thanks in advance

AL

 
Thanks, but this gives the same error.
 
Hi

Forget my last post. temp.Items(i) does indeed work.

I had some Read Receipts in my inbox. The error was caused when the code tried to open them. I deleted these and everything works fine.

Thanks

AL
 
Al

if you check the Class Property of the item to be olMail, you 'll bypass anything that 's not a mail.
 
Thanks Jerry

I've been trying to use Class Property but haven't quite got it right yet.

Do I use something like:

Code:
if temp.items(i).class = olMail

etc

I tried doing Debug.Print temp.items(i).class but this returned numbers, with e-mails and read receipts having the same number.

Getting this sorted would be the final piece in the jigsaw. Thanks for your help so far.

AL
 

temp.Items(i).Class = 43 is for mails
if you search for Class property you 'll get to the OlObjectClass constants

Code:
Sub Analyze_Email()
   Dim ns As Outlook.NameSpace
   Dim temp As Outlook.MAPIFolder
   Dim ItemsFound As Long
   Dim myItem As Object
   Dim i As Integer

   Dim MailsCount As Long
   
   Set ns = GetNamespace("MAPI")
   Set temp = ns.GetDefaultFolder(olFolderInbox)
   ItemsFound = temp.Items.Count
   Debug.Print ItemsFound
   For i = ItemsFound To 1 Step -1
     If temp.Items(i).Class = 43 Then MailsCount = MailsCount + 1
   Next
   Debug.Print MailsCount
   Set temp = Nothing
   Set ns = Nothing
End Sub

The previous returns 23 objects and 22 mails which is correct since in my mailbox currently exists one receipt.
 
Thanks again Jerry.

Everything's working now.

AL
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top