The error means just what it says: You're casting to the wrong class. Session.AddressBook is a CDO 1.21 method. Therefore, it returns a MAPI.Recipients object, not Outlook.Recipients.
Note, also, that CDO is officially unsupported in .NET languages. -- Sue Mosher, Outlook MVP Author of Configuring Microsoft Outlook 2003 http://www.turtleflock.com/olconfig/index.htm and Microsoft Outlook Programming - Jumpstart for Administrators, Power Users, and Developers http://www.outlookcode.com/article.aspx?id=54 "Dewey" <Dewey[ at ]discussions.microsoft.com> wrote in message news:04A2CAB5-C41F-48AB-A9B9-1BA4060EA74D[ at ]microsoft.com...
[Quoted Text] > Hi > I posted a quesiton earlier, but it hasn't showed up in over an hour, so > I'll post again, this time with more info. > So I'm tring to access the Outlook 2003 Address book from VB.net (using > VS.net 2005). I get the list open just fine using a call to > objSession.AddressBook( ). However, once a name is selected, I get an error > that reads: > > > "Unable to cast COM object of type 'System.__ComObject' to interface type > "Microsoft.Office.Interop.Outlook.Recipients'. This operation failed because > the QuesryInterface call on the COM component for the interface with IID > '{0006303B-0000-0000-C000-000000000046}' failed due to the following error: > No such interface supported (Exception from HRESULT: 0x80004002 > (E_NOINTERFACE))." > > > According to older documentation I found for VBA, the AddressBook( ) > function returns a Recipients object, but I'm not getting it back, even when > I explicitly try to cast the return using CType. Instead, I get the error > above. Can someone help me? > > Here's my code: > > > > Public Function AddressBook_Click(ByVal myChoice As String) As String > > Dim objNS As Microsoft.Office.Interop.Outlook.NameSpace > Dim objSession As Object 'As MAPI.Session > > Dim objRecipients As Microsoft.Office.Interop.Outlook.Recipients > > objSession = CreateObject("MAPI.Session") > objSession.Logon(, , False, False) > objRecipients = objSession.AddressBook(, "Please select", True, > True, 1, "mychoice") > > AddressBook_Click = objRecipients.Item(1).AddressEntry > > End Function > > > Thanks for your help! > -Josh
|