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 » Add-ins for Outlook
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Strange COM error



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old June 5th 07, 11:41 PM posted to microsoft.public.outlook.program_addins
Dewey
external usenet poster
 
Posts: 26
Default Strange COM error

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
Ads
  #2  
Old June 6th 07, 12:29 AM posted to microsoft.public.outlook.program_addins
Sue Mosher [MVP-Outlook]
external usenet poster
 
Posts: 11,651
Default Strange COM error

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

 




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
Strange error numbers when running code [email protected] Outlook and VBA 8 May 9th 07 12:15 PM
Strange error message Patch Outlook Express 3 February 26th 07 02:05 PM
Strange behaviour with Type Error Tobias Schröer Outlook and VBA 0 January 31st 07 10:48 AM
Strange error coming from OUTLOOK... Karan Outlook - General Queries 0 June 13th 06 06:36 AM
strange error cowboy Outlook Express 3 June 5th 06 07:40 AM


All times are GMT +1. The time now is 08:44 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.