Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Outlook / Interop / December 2004

Tip: Looking for answers? Try searching our database.

Outlook 2003 PIA Question

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Richard Waterson - 27 Dec 2004 14:52 GMT
I am trying to run this sample code but keep getting an "Invalid Cast"
exception when calling oItems.GetFirst and assigning the resulting
object to a ContactItem. The ItemsClass object has a count of 208
items, so I'm confident the collection contains all my contacts. Where
am I going wrong?

        ' Create Outlook application.
        Dim oApp As Outlook.Application = New
Outlook.Application

        ' Get namespace and Contacts folder reference.
        Dim oNS As Outlook.NameSpace =
oApp.GetNamespace("MAPI")
        Dim cContacts As Outlook.MAPIFolder =
oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts)

        ' Get the first contact from the Contacts folder.
        Dim oItems As Outlook.ItemsClass = cContacts.Items
        Dim oCt As Outlook.ContactItemClass

        Dim iCount As Int16
        iCount = 0
        oCt = oItems.GetFirst()

        Do While Not oCt Is Nothing

            iCount += 1

            Console.WriteLine(oCt.FullName)
            oCt = oItems.GetNext

        Loop

        Console.WriteLine(iCount)

        ' Clean up.
        oApp = Nothing
        oItems = Nothing
        oCt = Nothing
Peter Jausovec - 28 Dec 2004 09:25 GMT
Hi,

You should cast the object type to the ItemsClass and ContactItemClass where
is neccessary. (I am from C# background; don't know how the thing is done in
VB.NET :))

Signature

Regards,
Peter Jausovec
(http://blog.jausovec.net)

>I am trying to run this sample code but keep getting an "Invalid Cast"
> exception when calling oItems.GetFirst and assigning the resulting
[quoted text clipped - 35 lines]
> oItems = Nothing
> oCt = Nothing
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.