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

Smarter NameSpace Reference...



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old October 21st 07, 05:58 AM posted to microsoft.public.outlook.program_vba
DG
external usenet poster
 
Posts: 31
Default Smarter NameSpace Reference...

I am using the following code in a VB.Net 2005 add-in for Outlook 2003 and on
50% of my workstations I get a Cast Object error. So obviously my approach is
wrong:

Private Sub ThisApplication_Startup(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Startup
....
Dim objOutlook As Outlook._Application
objOutlook = New Outlook.Application()
Dim objNS As Outlook._NameSpace = objOutlook.Session
objFolder =
objNS.GetDefaultFolder(Outlook.OlDefaultFolders.ol FolderSentMail)
objFolderItems = objFolder.Items
AddHandler objFolderItems.ItemAdd, AddressOf objFolderItemAdded
....
End Sub

So I believe it's wrong to create a new Outlook session from within Outlook.
How else would I do it to avoid the cast error?

DG
  #2  
Old October 21st 07, 02:26 PM posted to microsoft.public.outlook.program_vba
Sue Mosher [MVP-Outlook]
external usenet poster
 
Posts: 11,651
Default Smarter NameSpace Reference...

Answered at http://www.outlookcode.com/threads.a...essageid=24546

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


"DG" wrote in message ...
I am using the following code in a VB.Net 2005 add-in for Outlook 2003 and on
50% of my workstations I get a Cast Object error. So obviously my approach is
wrong:

Private Sub ThisApplication_Startup(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Startup
...
Dim objOutlook As Outlook._Application
objOutlook = New Outlook.Application()
Dim objNS As Outlook._NameSpace = objOutlook.Session
objFolder =
objNS.GetDefaultFolder(Outlook.OlDefaultFolders.ol FolderSentMail)
objFolderItems = objFolder.Items
AddHandler objFolderItems.ItemAdd, AddressOf objFolderItemAdded
...
End Sub

So I believe it's wrong to create a new Outlook session from within Outlook.
How else would I do it to avoid the cast error?

DG

 




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
working with System.Net.Mail namespace rodchar Outlook - Using Forms 0 August 31st 07 03:10 PM
NameSpace.GetItemFromID() threw an exception OctopusThu Add-ins for Outlook 2 December 15th 06 06:40 AM
Outlook View Control : urn.schemas.httpmail namespace [email protected] Outlook - Using Forms 1 November 30th 06 04:34 PM
nameSpace.OptionsPagesAdd Ralf Jansen Add-ins for Outlook 2 May 12th 06 03:01 PM
GetItemFromID method on a public folder in the namespace Robert Squire Outlook and VBA 1 February 24th 06 01:31 PM


All times are GMT +1. The time now is 10:39 AM.


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.