Wrox Programmer Forums
|
Pro VB.NET 2002/2003 For advanced Visual Basic coders working .NET version 2002/2003. Beginning-level questions will be redirected to other forums, including Beginning VB.NET.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro VB.NET 2002/2003 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 28th, 2003, 09:09 AM
Authorized User
 
Join Date: Jun 2003
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
Default Outlook 2000 errors

Hi all,

I am new to .net and I have upgraded a VB6 project to .net using the upgrade wizard.

I have resolved most of the errors however I have an error with a MAPI Folder.

My code is

Private m_objCurrentFolder As Outlook.MAPIFolder

 For Each objItem In m_objCurrentFolder.Items
            Select Case objItem.Class
                Case Outlook.OlObjectClass.olMail
                    If Subject <> "" Then

                        If objItem.Subject = Subject Then
                            ReDim Preserve arrItems(4, i)
                            arrItems(0, i).Add(objItem.EntryID)
                            arrItems(1, i).Add(objItem.SentOn)
                            arrItems(2, i).Add(objItem.ReceivedTime)
                            arrItems(3, i).Add(objItem.Subject)
                            If objItem.Body <> "" Then
                                arrItems(4, i).Add(objItem.Body)
                            Else
                                arrItems(4, i).Add(objItem.HTMLBody)
                            End If
                            i = i + 1
                        End If
                    Else
                        ReDim Preserve arrItems(4, i)
                        arrItems(0, i).Add(objItem.EntryID)
                        arrItems(1, i).Add(objItem.SentOn)
                        arrItems(2, i).Add(objItem.ReceivedTime)
                        arrItems(3, i).Add(objItem.Subject)

                        If objItem.Body <> "" Then
                            arrItems(4, i).Add(objItem.Body)
                        Else
                            arrItems(4, i).Add(objItem.HTMLBody)
                        End If
                        i = i + 1
                    End If
            End Select
        Next objItem

The error is with the first line
For Each objItem In m_objCurrentFolder.Items

And the error is
C:\Documents and Settings\Administrator\Desktop\byrons\MyDocs\Custo mers\C\CBT\CBTAutoMail\CBTAutoMail.NET\bsolOutlook 2000.vb(539): Expression is of type 'Outlook.Items', which is not a collection type.

Can anyone please help.

Thanks in advance

Byron
 
Old December 1st, 2003, 09:56 AM
Registered User
 
Join Date: Dec 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Biron,

I get the same error with Outlook 2002.
Have you solved it yet?

Manana

 
Old December 1st, 2003, 10:06 AM
Authorized User
 
Join Date: Jun 2003
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I didn't solve it as such, I tackled it from a different perspective.
As I knew that the only items I was interested in had a specific subject, I changed the code as below.

Hope this helps


Dim objItem As Object
        Dim arrItems(4, 0) As Object
        Dim i As Integer
        Dim x As Integer
        Dim replyadd As String

        On Error GoTo PROC_ERR
        For x = 1 To m_objCurrentFolder.Items.Count
            objItem = m_objCurrentFolder.Items.Item(x)
            If Subject <> "" Then
                If objItem.Subject = Subject Then
                    ReDim Preserve arrItems(4, i)
                    arrItems(0, i) = (objItem.EntryID)
                    arrItems(1, i) = (objItem.SentOn)
                    arrItems(2, i) = (objItem.ReceivedTime)
                    arrItems(3, i) = (objItem.Subject)
                    If objItem.Body <> "" Then
                        arrItems(4, i) = (objItem.Body)
                    Else
                        arrItems(4, i) = (objItem.HTMLBody)
                    End If
                    i = i + 1
                End If
            Else
                ReDim Preserve arrItems(4, i)
                arrItems(0, i) = (objItem.EntryID)
                arrItems(1, i) = (objItem.SentOn)
                arrItems(2, i) = (objItem.ReceivedTime)
                arrItems(3, i) = (objItem.Subject)
                If objItem.Body <> "" Then
                    arrItems(4, i).Add(objItem.Body)
                Else
                    arrItems(4, i).Add(objItem.HTMLBody)
                End If
                i = i + 1
            End If
        Next

 
Old December 1st, 2003, 10:17 AM
Registered User
 
Join Date: Dec 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Biron,

Thanks. I solved it by reading the Folder.Items into an object (which now does support for each etc.)

Dim objApp As Outlook.Application
        Dim objNameSpace As Outlook.NameSpace
        Dim objMAPIFolder As Outlook.MAPIFolder
        Dim objMailItem As Outlook.MailItem
        Dim i As Integer

        objApp = New Outlook.Application
        objNameSpace = objApp.GetNamespace(Type:="MAPI")
        objMAPIFolder = objNameSpace.GetDefaultFolder(Outlook.OlDefaultFol ders.olFolderInbox)

        Dim objItems As Object

        objItems = objMAPIFolder.Items
        'This is a workaround because "objMAPIFolder.Items" does not support iteration (bug?)

        For Each objMailItem In objItems
            Debug.WriteLine(objMailItem.Subject)
        Next







Similar Threads
Thread Thread Starter Forum Replies Last Post
Outlook 2000 Contacts into Access MWiseman Access VBA 5 January 27th, 2005 02:32 PM
MS Outlook 2000 procedure cunninb VB How-To 0 January 5th, 2005 08:40 PM
Outlook 2000 errors byron VB.NET 2002/2003 Basics 0 August 28th, 2003 09:08 AM
Access 2000 and Outlook vaheh Access VBA 1 August 13th, 2003 03:18 PM
Outlook 2000 Automation byron Pro VB 6 4 July 10th, 2003 01:10 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.