Security Message When Accessing SentOnBehalfOfName

N

nacooke

Hi

I have two exchange accounts open at once (my personal account and a
shared account). When I send messages from the shared account the
message is stored in "Sent Items" of my personal account. As I would
like these mails to be stored in the "Sent Items" of the shared
account I wrote some code to do move the sent item: (this is an
extract of the code)

Private Sub objSentItems_ItemAdd(ByVal Item As Object)
'Fired when something is added to personal "Sent Mail" folder
If TypeName(Item) = "MailItem" Then
If Item.SentOnBehalfOfName = "Shared Account" Then
Set DestinationFolder =
Application.Session.GetFolderFromID(SentEntryID, SentStoreID)
Item.Move (DestinationFolder)
End If
End If
End Sub

This works fine on my PC and one of my colleague's, however another
colleague's PC displays the security alert ("A program is trying to
access e-mail addresses stored in Outlook. Do you want to allow
this?").

The line that appears to be generating is "If Item.SentOnBehalfOfName
= "Shared Account" Then".

All three PCs are Outlook 2003.

Any ideas on what could be causing this behaviour?

Many thanks

N A Cooke
 
M

Michael Bauer [MVP - Outlook]

Weird that it works on some OL 2003 and on another it doesn't.

If it doesn't work on all OL 2003 systems then I'd suggest to modify your
code like this:

Dim Mail as Outlook.MailItem

If TypeOf Item is Outlook.MailItem then
With Item
Set Mail =
Application.GetNamespace("mapi").GetItemFromID(.EntryID,.Parent.StoreID)
End With
Endif

And then work with the new variable Mail instead of Item.

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
Keep your Outlook categories organized!
http://www.shareit.com/product.html?productid=300120654&languageid=1
(German: http://www.VBOffice.net/product.html?pub=6)


Am 14 Feb 2007 08:20:13 -0800 schrieb (e-mail address removed):
 
N

nacooke

Thanks Michael,

I am still getting the same error. I replaced my code with:

Private Sub objSentItems_ItemAdd(ByVal Item As Object)
'Fired when something is added to personal "Sent Mail" folder
If TypeOf Item Is Outlook.MailItem Then
With Item
Set MailItem =
Application.GetNamespace("mapi").GetItemFromID(.EntryID, .Parent.StoreID)
End With
If MailItem.SenderName = "Shared Account" Then
Set DestinationFolder =
Application.Session.GetFolderFromID(SentEntryID, SentStoreID)
MailItem.Move (DestinationFolder)
End If
End If
Set MailItem = Nothing
End Sub

Any other ideas anyone? This is the first Outlook code I've produced
(usually Word & Excel) so please feel free to suggest anything
obvious! Are there any settings/options that could be causing this
behaviour?
 
D

Dmitry Streblechenko

Where does your code live? Is it in a COM addin, standalone exe, etc?
In case of a COM add-in, how do you retrieve Outlook.Application?

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
N

nacooke

The code is in the ThisOutlookSession module in VBAProject.otm. This
has been copied and pasted into the same location on my colleagues
computers.
 
D

Dmitry Streblechenko

Hmmm... Than it should work perfectly fine... Are you sure it is that line?

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

The code is in the ThisOutlookSession module in VBAProject.otm. This
has been copied and pasted into the same location on my colleagues
computers.

Where does your code live? Is it in a COM addin, standalone exe, etc?
In case of a COM add-in, how do you retrieve Outlook.Application?

Dmitry Streblechenko (MVP)http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool




Thanks Michael,
I am still getting the same error. I replaced my code with:
Private Sub objSentItems_ItemAdd(ByVal Item As Object)
'Fired when something is added to personal "Sent Mail" folder
If TypeOf Item Is Outlook.MailItem Then
With Item
Set MailItem =
Application.GetNamespace("mapi").GetItemFromID(.EntryID,
.Parent.StoreID)
End With
If MailItem.SenderName = "Shared Account" Then
Set DestinationFolder =
Application.Session.GetFolderFromID(SentEntryID, SentStoreID)
MailItem.Move (DestinationFolder)
End If
End If
Set MailItem = Nothing
End Sub
Any other ideas anyone? This is the first Outlook code I've produced
(usually Word & Excel) so please feel free to suggest anything
obvious! Are there any settings/options that could be causing this
behaviour?
On 15 Feb, 06:27, "Michael Bauer [MVP - Outlook]" <[email protected]>
wrote:
Weird that it works on some OL 2003 and on another it doesn't.
If it doesn't work on all OL 2003 systems then I'd suggest to modify
your
code like this:
Dim Mail as Outlook.MailItem
If TypeOf Item is Outlook.MailItem then
With Item
Set Mail =
Application.GetNamespace("mapi").GetItemFromID(.EntryID,.Parent.StoreID)
End With
Endif
And then work with the new variable Mail instead of Item.
--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
Keep your Outlook categories organized!
http://www.shareit.com/product.html?productid=300120654&languageid=1
(German:http://www.VBOffice.net/product.html?pub=6)
Am 14 Feb 2007 08:20:13 -0800 schrieb (e-mail address removed):

I have two exchange accounts open at once (my personal account and a
shared account). When I send messages from the shared account the
message is stored in "Sent Items" of my personal account. As I
would
like these mails to be stored in the "Sent Items" of the shared
account I wrote some code to do move the sent item: (this is an
extract of the code)
Private Sub objSentItems_ItemAdd(ByVal Item As Object)
'Fired when something is added to personal "Sent Mail" folder
If TypeName(Item) = "MailItem" Then
If Item.SentOnBehalfOfName = "Shared Account" Then
Set DestinationFolder =
Application.Session.GetFolderFromID(SentEntryID, SentStoreID)
Item.Move (DestinationFolder)
End If
End If
End Sub
This works fine on my PC and one of my colleague's, however another
colleague's PC displays the security alert ("A program is trying to
access e-mail addresses stored in Outlook. Do you want to allow
this?").
The line that appears to be generating is "If
Item.SentOnBehalfOfName
= "Shared Account" Then".
All three PCs are Outlook 2003.
Any ideas on what could be causing this behaviour?
Many thanks
N A Cooke- Hide quoted text -
- Show quoted text -- Hide quoted text -

- Show quoted text -
 
N

nacooke

Yes, it's when accessing SentOnBehalfOfName in the original code, or
MailItem.SenderName in the code suggested by Michael. (I identified
this by stepping through the code to see which line threw the error).

Hmmm... Than it should work perfectly fine... Are you sure it is that line?

Dmitry Streblechenko (MVP)http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool


The code is in the ThisOutlookSession module in VBAProject.otm. This
has been copied and pasted into the same location on my colleagues
computers.
Where does your code live? Is it in a COM addin, standalone exe, etc?
In case of a COM add-in, how do you retrieve Outlook.Application?
Dmitry Streblechenko (MVP)http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

Thanks Michael,
I am still getting the same error. I replaced my code with:
Private Sub objSentItems_ItemAdd(ByVal Item As Object)
'Fired when something is added to personal "Sent Mail" folder
If TypeOf Item Is Outlook.MailItem Then
With Item
Set MailItem =
Application.GetNamespace("mapi").GetItemFromID(.EntryID,
.Parent.StoreID)
End With
If MailItem.SenderName = "Shared Account" Then
Set DestinationFolder =
Application.Session.GetFolderFromID(SentEntryID, SentStoreID)
MailItem.Move (DestinationFolder)
End If
End If
Set MailItem = Nothing
End Sub
Any other ideas anyone? This is the first Outlook code I've produced
(usually Word & Excel) so please feel free to suggest anything
obvious! Are there any settings/options that could be causing this
behaviour?
On 15 Feb, 06:27, "Michael Bauer [MVP - Outlook]" <[email protected]>
wrote:
Weird that it works on some OL 2003 and on another it doesn't.
If it doesn't work on all OL 2003 systems then I'd suggest to modify
your
code like this:
Dim Mail as Outlook.MailItem
If TypeOf Item is Outlook.MailItem then
With Item
Set Mail =
Application.GetNamespace("mapi").GetItemFromID(.EntryID,.Parent.StoreID)
End With
Endif
And then work with the new variable Mail instead of Item.
--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
Keep your Outlook categories organized!
http://www.shareit.com/product.html?productid=300120654&languageid=1
(German:http://www.VBOffice.net/product.html?pub=6)
Am 14 Feb 2007 08:20:13 -0800 schrieb (e-mail address removed):
Hi
I have two exchange accounts open at once (my personal account and a
shared account). When I send messages from the shared account the
message is stored in "Sent Items" of my personal account. As I
would
like these mails to be stored in the "Sent Items" of the shared
account I wrote some code to do move the sent item: (this is an
extract of the code)
Private Sub objSentItems_ItemAdd(ByVal Item As Object)
'Fired when something is added to personal "Sent Mail" folder
If TypeName(Item) = "MailItem" Then
If Item.SentOnBehalfOfName = "Shared Account" Then
Set DestinationFolder =
Application.Session.GetFolderFromID(SentEntryID, SentStoreID)
Item.Move (DestinationFolder)
End If
End If
End Sub
This works fine on my PC and one of my colleague's, however another
colleague's PC displays the security alert ("A program is trying to
access e-mail addresses stored in Outlook. Do you want to allow
this?").
The line that appears to be generating is "If
Item.SentOnBehalfOfName
= "Shared Account" Then".
All three PCs are Outlook 2003.
Any ideas on what could be causing this behaviour?
Many thanks
N A Cooke- Hide quoted text -
- Show quoted text -- Hide quoted text -
- Show quoted text -
 
D

Dmitry Streblechenko

Hmmm.. And you never reset the Application intrinsic variable, right?

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

Yes, it's when accessing SentOnBehalfOfName in the original code, or
MailItem.SenderName in the code suggested by Michael. (I identified
this by stepping through the code to see which line threw the error).

Hmmm... Than it should work perfectly fine... Are you sure it is that
line?

Dmitry Streblechenko (MVP)http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool


The code is in the ThisOutlookSession module in VBAProject.otm. This
has been copied and pasted into the same location on my colleagues
computers.
Where does your code live? Is it in a COM addin, standalone exe, etc?
In case of a COM add-in, how do you retrieve Outlook.Application?
Dmitry Streblechenko (MVP)http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
Thanks Michael,
I am still getting the same error. I replaced my code with:
Private Sub objSentItems_ItemAdd(ByVal Item As Object)
'Fired when something is added to personal "Sent Mail" folder
If TypeOf Item Is Outlook.MailItem Then
With Item
Set MailItem =
Application.GetNamespace("mapi").GetItemFromID(.EntryID,
.Parent.StoreID)
End With
If MailItem.SenderName = "Shared Account" Then
Set DestinationFolder =
Application.Session.GetFolderFromID(SentEntryID, SentStoreID)
MailItem.Move (DestinationFolder)
End If
End If
Set MailItem = Nothing
End Sub
Any other ideas anyone? This is the first Outlook code I've
produced
(usually Word & Excel) so please feel free to suggest anything
obvious! Are there any settings/options that could be causing this
behaviour?
On 15 Feb, 06:27, "Michael Bauer [MVP - Outlook]" <[email protected]>
wrote:
Weird that it works on some OL 2003 and on another it doesn't.
If it doesn't work on all OL 2003 systems then I'd suggest to
modify
your
code like this:
Dim Mail as Outlook.MailItem
If TypeOf Item is Outlook.MailItem then
With Item
Set Mail =
Application.GetNamespace("mapi").GetItemFromID(.EntryID,.Parent.StoreID)
End With
Endif
And then work with the new variable Mail instead of Item.
--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
Keep your Outlook categories organized!

http://www.shareit.com/product.html?productid=300120654&languageid=1
(German:http://www.VBOffice.net/product.html?pub=6)
Am 14 Feb 2007 08:20:13 -0800 schrieb (e-mail address removed):

I have two exchange accounts open at once (my personal account
and a
shared account). When I send messages from the shared account
the
message is stored in "Sent Items" of my personal account. As I
would
like these mails to be stored in the "Sent Items" of the shared
account I wrote some code to do move the sent item: (this is an
extract of the code)
Private Sub objSentItems_ItemAdd(ByVal Item As Object)
'Fired when something is added to personal "Sent Mail" folder
If TypeName(Item) = "MailItem" Then
If Item.SentOnBehalfOfName = "Shared Account" Then
Set DestinationFolder =
Application.Session.GetFolderFromID(SentEntryID, SentStoreID)
Item.Move (DestinationFolder)
End If
End If
End Sub
This works fine on my PC and one of my colleague's, however
another
colleague's PC displays the security alert ("A program is trying
to
access e-mail addresses stored in Outlook. Do you want to allow
this?").
The line that appears to be generating is "If
Item.SentOnBehalfOfName
= "Shared Account" Then".
All three PCs are Outlook 2003.
Any ideas on what could be causing this behaviour?
Many thanks
N A Cooke- Hide quoted text -
- Show quoted text -- Hide quoted text -
- Show quoted text -
 
N

nacooke

Not as far as I am aware. All the code does is identify which sent
folder to use (on Application startup), and then the only code is the
bits I posted earlier. I'll post the whole code tomorrow if that is
of use (am not at work now).

Thanks

Nick

Hmmm.. And you never reset the Application intrinsic variable, right?

Dmitry Streblechenko (MVP)http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool


Yes, it's when accessing SentOnBehalfOfName in the original code, or
MailItem.SenderName in the code suggested by Michael. (I identified
this by stepping through the code to see which line threw the error).
Hmmm... Than it should work perfectly fine... Are you sure it is that
line?
Dmitry Streblechenko (MVP)http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

The code is in the ThisOutlookSession module in VBAProject.otm. This
has been copied and pasted into the same location on my colleagues
computers.
Where does your code live? Is it in a COM addin, standalone exe, etc?
In case of a COM add-in, how do you retrieve Outlook.Application?
Dmitry Streblechenko (MVP)http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

Thanks Michael,
I am still getting the same error. I replaced my code with:
Private Sub objSentItems_ItemAdd(ByVal Item As Object)
'Fired when something is added to personal "Sent Mail" folder
If TypeOf Item Is Outlook.MailItem Then
With Item
Set MailItem =
Application.GetNamespace("mapi").GetItemFromID(.EntryID,
.Parent.StoreID)
End With
If MailItem.SenderName = "Shared Account" Then
Set DestinationFolder =
Application.Session.GetFolderFromID(SentEntryID, SentStoreID)
MailItem.Move (DestinationFolder)
End If
End If
Set MailItem = Nothing
End Sub
Any other ideas anyone? This is the first Outlook code I've
produced
(usually Word & Excel) so please feel free to suggest anything
obvious! Are there any settings/options that could be causing this
behaviour?
On 15 Feb, 06:27, "Michael Bauer [MVP - Outlook]" <[email protected]>
wrote:
Weird that it works on some OL 2003 and on another it doesn't.
If it doesn't work on all OL 2003 systems then I'd suggest to
modify
your
code like this:
Dim Mail as Outlook.MailItem
If TypeOf Item is Outlook.MailItem then
With Item
Set Mail =
Application.GetNamespace("mapi").GetItemFromID(.EntryID,.Parent.StoreID)
End With
Endif
And then work with the new variable Mail instead of Item.
--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
Keep your Outlook categories organized!
http://www.shareit.com/product.html?productid=300120654&languageid=1
(German:http://www.VBOffice.net/product.html?pub=6)
Am 14 Feb 2007 08:20:13 -0800 schrieb (e-mail address removed):
Hi
I have two exchange accounts open at once (my personal account
and a
shared account). When I send messages from the shared account
the
message is stored in "Sent Items" of my personal account. As I
would
like these mails to be stored in the "Sent Items" of the shared
account I wrote some code to do move the sent item: (this is an
extract of the code)
Private Sub objSentItems_ItemAdd(ByVal Item As Object)
'Fired when something is added to personal "Sent Mail" folder
If TypeName(Item) = "MailItem" Then
If Item.SentOnBehalfOfName = "Shared Account" Then
Set DestinationFolder =
Application.Session.GetFolderFromID(SentEntryID, SentStoreID)
Item.Move (DestinationFolder)
End If
End If
End Sub
This works fine on my PC and one of my colleague's, however
another
colleague's PC displays the security alert ("A program is trying
to
access e-mail addresses stored in Outlook. Do you want to allow
this?").
The line that appears to be generating is "If
Item.SentOnBehalfOfName
= "Shared Account" Then".
All three PCs are Outlook 2003.
Any ideas on what could be causing this behaviour?
Many thanks
N A Cooke- Hide quoted text -
- Show quoted text -- Hide quoted text -
- Show quoted text -
 
N

nacooke

Here's the full code I'm using:
*********************************************************************************************************************************************
Private SentEntryID As String
Private SentStoreID As String
Private WithEvents objSentItems As Items
Private MailItem As Outlook.MailItem

Public Sub Application_Startup()
'Retrieve ID for accessing non-default sent folder
getStoreFolderID ("Mailbox - Shared Account")
Set objSentItems =
Application.Session.GetDefaultFolder(olFolderSentMail).Items
End Sub

Function getStoreFolderID(StoreName)
'Gets the Shared Account Sent Folder
Dim Store As Object
Dim StoreFolder As Object
Dim i As Integer
Set Store = Application.GetNamespace("MAPI").Folders
For Each StoreFolder In Store
If StoreFolder.Name = StoreName Then
For i = 1 To StoreFolder.Folders.Count
If StoreFolder.Folders(i).Name = "Sent Items" Then
SentEntryID = StoreFolder.Folders(i).EntryID
SentStoreID = StoreFolder.Folders(i).StoreID
Exit For
End If
Next
Exit For
End If
Next
Set Store = Nothing
Set StoreFolder = Nothing
End Function

Private Sub objSentItems_ItemAdd(ByVal Item As Object)
'Fired when something is added to personal "Sent Mail" folder
If TypeOf Item Is Outlook.MailItem Then
With Item
Set MailItem =
Application.GetNamespace("mapi").GetItemFromID(.EntryID, .Parent.StoreID)
End With
If MailItem.SenderName = "Shared Account" Then
Set DestinationFolder =
Application.Session.GetFolderFromID(SentEntryID, SentStoreID)
MailItem.Move (DestinationFolder)
End If
End If
Set MailItem = Nothing
End Sub

Not as far as I am aware. All the code does is identify which sent
folder to use (on Application startup), and then the only code is the
bits I posted earlier. I'll post the whole code tomorrow if that is
of use (am not at work now).

Thanks

Nick

Hmmm.. And you never reset the Application intrinsic variable, right?
Dmitry Streblechenko (MVP)http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
Yes, it's when accessing SentOnBehalfOfName in the original code, or
MailItem.SenderName in the code suggested by Michael. (I identified
this by stepping through the code to see which line threw the error).
Hmmm... Than it should work perfectly fine... Are you sure it is that
line?
Dmitry Streblechenko (MVP)http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

The code is in the ThisOutlookSession module in VBAProject.otm. This
has been copied and pasted into the same location on my colleagues
computers.
Where does your code live? Is it in a COM addin, standalone exe, etc?
In case of a COM add-in, how do you retrieve Outlook.Application?
Dmitry Streblechenko (MVP)http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

Thanks Michael,
I am still getting the same error. I replaced my code with:
Private Sub objSentItems_ItemAdd(ByVal Item As Object)
'Fired when something is added to personal "Sent Mail" folder
If TypeOf Item Is Outlook.MailItem Then
With Item
Set MailItem =
Application.GetNamespace("mapi").GetItemFromID(.EntryID,
.Parent.StoreID)
End With
If MailItem.SenderName = "Shared Account" Then
Set DestinationFolder =
Application.Session.GetFolderFromID(SentEntryID, SentStoreID)
MailItem.Move (DestinationFolder)
End If
End If
Set MailItem = Nothing
End Sub
Any other ideas anyone? This is the first Outlook code I've
produced
(usually Word & Excel) so please feel free to suggest anything
obvious! Are there any settings/options that could be causing this
behaviour?
On 15 Feb, 06:27, "Michael Bauer [MVP - Outlook]" <[email protected]>
wrote:
Weird that it works on some OL 2003 and on another it doesn't.
If it doesn't work on all OL 2003 systems then I'd suggest to
modify
your
code like this:
Dim Mail as Outlook.MailItem
If TypeOf Item is Outlook.MailItem then
With Item
Set Mail =
Application.GetNamespace("mapi").GetItemFromID(.EntryID,.Parent.StoreID)
End With
Endif
And then work with the new variable Mail instead of Item.
--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
Keep your Outlook categories organized!
http://www.shareit.com/product.html?productid=300120654&languageid=1
(German:http://www.VBOffice.net/product.html?pub=6)
Am 14 Feb 2007 08:20:13 -0800 schrieb (e-mail address removed):
Hi
I have two exchange accounts open at once (my personal account
and a
shared account). When I send messages from the shared account
the
message is stored in "Sent Items" of my personal account. As I
would
like these mails to be stored in the "Sent Items" of the shared
account I wrote some code to do move the sent item: (this is an
extract of the code)
Private Sub objSentItems_ItemAdd(ByVal Item As Object)
'Fired when something is added to personal "Sent Mail" folder
If TypeName(Item) = "MailItem" Then
If Item.SentOnBehalfOfName = "Shared Account" Then
Set DestinationFolder =
Application.Session.GetFolderFromID(SentEntryID, SentStoreID)
Item.Move (DestinationFolder)
End If
End If
End Sub
This works fine on my PC and one of my colleague's, however
another
colleague's PC displays the security alert ("A program is trying
to
access e-mail addresses stored in Outlook. Do you want to allow
this?").
The line that appears to be generating is "If
Item.SentOnBehalfOfName
= "Shared Account" Then".
All three PCs are Outlook 2003.
Any ideas on what could be causing this behaviour?
Many thanks
N A Cooke- Hide quoted text -
- Show quoted text -- Hide quoted text -
- Show quoted text -- Hide quoted text -

- Show quoted text -
 
D

Dmitry Streblechenko

I can't think of anything that can possibly be wrong, sorry...

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

Here's the full code I'm using:
*********************************************************************************************************************************************
Private SentEntryID As String
Private SentStoreID As String
Private WithEvents objSentItems As Items
Private MailItem As Outlook.MailItem

Public Sub Application_Startup()
'Retrieve ID for accessing non-default sent folder
getStoreFolderID ("Mailbox - Shared Account")
Set objSentItems =
Application.Session.GetDefaultFolder(olFolderSentMail).Items
End Sub

Function getStoreFolderID(StoreName)
'Gets the Shared Account Sent Folder
Dim Store As Object
Dim StoreFolder As Object
Dim i As Integer
Set Store = Application.GetNamespace("MAPI").Folders
For Each StoreFolder In Store
If StoreFolder.Name = StoreName Then
For i = 1 To StoreFolder.Folders.Count
If StoreFolder.Folders(i).Name = "Sent Items" Then
SentEntryID = StoreFolder.Folders(i).EntryID
SentStoreID = StoreFolder.Folders(i).StoreID
Exit For
End If
Next
Exit For
End If
Next
Set Store = Nothing
Set StoreFolder = Nothing
End Function

Private Sub objSentItems_ItemAdd(ByVal Item As Object)
'Fired when something is added to personal "Sent Mail" folder
If TypeOf Item Is Outlook.MailItem Then
With Item
Set MailItem =
Application.GetNamespace("mapi").GetItemFromID(.EntryID, .Parent.StoreID)
End With
If MailItem.SenderName = "Shared Account" Then
Set DestinationFolder =
Application.Session.GetFolderFromID(SentEntryID, SentStoreID)
MailItem.Move (DestinationFolder)
End If
End If
Set MailItem = Nothing
End Sub

Not as far as I am aware. All the code does is identify which sent
folder to use (on Application startup), and then the only code is the
bits I posted earlier. I'll post the whole code tomorrow if that is
of use (am not at work now).

Thanks

Nick

Hmmm.. And you never reset the Application intrinsic variable, right?
Dmitry Streblechenko (MVP)http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
Yes, it's when accessing SentOnBehalfOfName in the original code, or
MailItem.SenderName in the code suggested by Michael. (I identified
this by stepping through the code to see which line threw the error).
Hmmm... Than it should work perfectly fine... Are you sure it is
that
line?
Dmitry Streblechenko (MVP)http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
The code is in the ThisOutlookSession module in VBAProject.otm.
This
has been copied and pasted into the same location on my colleagues
computers.
On 15 Feb, 17:29, "Dmitry Streblechenko" <[email protected]>
wrote:
Where does your code live? Is it in a COM addin, standalone exe,
etc?
In case of a COM add-in, how do you retrieve Outlook.Application?
Dmitry Streblechenko (MVP)http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
Thanks Michael,
I am still getting the same error. I replaced my code with:
Private Sub objSentItems_ItemAdd(ByVal Item As Object)
'Fired when something is added to personal "Sent Mail"
folder
If TypeOf Item Is Outlook.MailItem Then
With Item
Set MailItem =
Application.GetNamespace("mapi").GetItemFromID(.EntryID,
.Parent.StoreID)
End With
If MailItem.SenderName = "Shared Account" Then
Set DestinationFolder =
Application.Session.GetFolderFromID(SentEntryID, SentStoreID)
MailItem.Move (DestinationFolder)
End If
End If
Set MailItem = Nothing
End Sub
Any other ideas anyone? This is the first Outlook code I've
produced
(usually Word & Excel) so please feel free to suggest anything
obvious! Are there any settings/options that could be causing
this
behaviour?
On 15 Feb, 06:27, "Michael Bauer [MVP - Outlook]"
<[email protected]>
wrote:
Weird that it works on some OL 2003 and on another it doesn't.
If it doesn't work on all OL 2003 systems then I'd suggest to
modify
your
code like this:
Dim Mail as Outlook.MailItem
If TypeOf Item is Outlook.MailItem then
With Item
Set Mail =
Application.GetNamespace("mapi").GetItemFromID(.EntryID,.Parent.StoreID)
End With
Endif
And then work with the new variable Mail instead of Item.
--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
Keep your Outlook categories organized!

Am 14 Feb 2007 08:20:13 -0800 schrieb (e-mail address removed):

I have two exchange accounts open at once (my personal
account
and a
shared account). When I send messages from the shared
account
the
message is stored in "Sent Items" of my personal account.
As I
would
like these mails to be stored in the "Sent Items" of the
shared
account I wrote some code to do move the sent item: (this is
an
extract of the code)
Private Sub objSentItems_ItemAdd(ByVal Item As Object)
'Fired when something is added to personal "Sent Mail"
folder
If TypeName(Item) = "MailItem" Then
If Item.SentOnBehalfOfName = "Shared Account" Then
Set DestinationFolder =
Application.Session.GetFolderFromID(SentEntryID,
SentStoreID)
Item.Move (DestinationFolder)
End If
End If
End Sub
This works fine on my PC and one of my colleague's, however
another
colleague's PC displays the security alert ("A program is
trying
to
access e-mail addresses stored in Outlook. Do you want to
allow
this?").
The line that appears to be generating is "If
Item.SentOnBehalfOfName
= "Shared Account" Then".
All three PCs are Outlook 2003.
Any ideas on what could be causing this behaviour?
Many thanks
N A Cooke- Hide quoted text -
- Show quoted text -- Hide quoted text -
- Show quoted text -- Hide quoted text -

- Show quoted text -
 
M

Michael Bauer [MVP - Outlook]

Please re-check that your colleague's PC really runs OL 2003, because it
behaves like OL XP.

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
Keep your Outlook categories organized!
http://www.shareit.com/product.html?productid=300120654&languageid=1
(German: http://www.VBOffice.net/product.html?pub=6)


Am 16 Feb 2007 00:54:21 -0800 schrieb (e-mail address removed):
Here's the full code I'm using:
*********************************************************************************************************************************************
Private SentEntryID As String
Private SentStoreID As String
Private WithEvents objSentItems As Items
Private MailItem As Outlook.MailItem

Public Sub Application_Startup()
'Retrieve ID for accessing non-default sent folder
getStoreFolderID ("Mailbox - Shared Account")
Set objSentItems =
Application.Session.GetDefaultFolder(olFolderSentMail).Items
End Sub

Function getStoreFolderID(StoreName)
'Gets the Shared Account Sent Folder
Dim Store As Object
Dim StoreFolder As Object
Dim i As Integer
Set Store = Application.GetNamespace("MAPI").Folders
For Each StoreFolder In Store
If StoreFolder.Name = StoreName Then
For i = 1 To StoreFolder.Folders.Count
If StoreFolder.Folders(i).Name = "Sent Items" Then
SentEntryID = StoreFolder.Folders(i).EntryID
SentStoreID = StoreFolder.Folders(i).StoreID
Exit For
End If
Next
Exit For
End If
Next
Set Store = Nothing
Set StoreFolder = Nothing
End Function

Private Sub objSentItems_ItemAdd(ByVal Item As Object)
'Fired when something is added to personal "Sent Mail" folder
If TypeOf Item Is Outlook.MailItem Then
With Item
Set MailItem =
Application.GetNamespace("mapi").GetItemFromID(.EntryID, .Parent.StoreID)
End With
If MailItem.SenderName = "Shared Account" Then
Set DestinationFolder =
Application.Session.GetFolderFromID(SentEntryID, SentStoreID)
MailItem.Move (DestinationFolder)
End If
End If
Set MailItem = Nothing
End Sub

Not as far as I am aware. All the code does is identify which sent
folder to use (on Application startup), and then the only code is the
bits I posted earlier. I'll post the whole code tomorrow if that is
of use (am not at work now).

Thanks

Nick

Hmmm.. And you never reset the Application intrinsic variable, right?
Dmitry Streblechenko (MVP)http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
Yes, it's when accessing SentOnBehalfOfName in the original code, or
MailItem.SenderName in the code suggested by Michael. (I identified
this by stepping through the code to see which line threw the error).
Hmmm... Than it should work perfectly fine... Are you sure it is that
line?
Dmitry Streblechenko (MVP)http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

The code is in the ThisOutlookSession module in VBAProject.otm. This
has been copied and pasted into the same location on my colleagues
computers.
Where does your code live? Is it in a COM addin, standalone exe, etc?
In case of a COM add-in, how do you retrieve Outlook.Application?
Dmitry Streblechenko (MVP)http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
Thanks Michael,
I am still getting the same error. I replaced my code with:
Private Sub objSentItems_ItemAdd(ByVal Item As Object)
'Fired when something is added to personal "Sent Mail" folder
If TypeOf Item Is Outlook.MailItem Then
With Item
Set MailItem =
Application.GetNamespace("mapi").GetItemFromID(.EntryID,
.Parent.StoreID)
End With
If MailItem.SenderName = "Shared Account" Then
Set DestinationFolder =
Application.Session.GetFolderFromID(SentEntryID, SentStoreID)
MailItem.Move (DestinationFolder)
End If
End If
Set MailItem = Nothing
End Sub
Any other ideas anyone? This is the first Outlook code I've
produced
(usually Word & Excel) so please feel free to suggest anything
obvious! Are there any settings/options that could be causing this
behaviour?
On 15 Feb, 06:27, "Michael Bauer [MVP - Outlook]"
wrote:
Weird that it works on some OL 2003 and on another it doesn't.
If it doesn't work on all OL 2003 systems then I'd suggest to
modify
your
code like this:
Dim Mail as Outlook.MailItem
If TypeOf Item is Outlook.MailItem then
With Item
Set Mail =
Application.GetNamespace("mapi").GetItemFromID(.EntryID,.Parent.StoreID)
End With
Endif
And then work with the new variable Mail instead of Item.
http://www.shareit.com/product.html?productid=300120654&languageid=1

Am 14 Feb 2007 08:20:13 -0800 schrieb (e-mail address removed):

I have two exchange accounts open at once (my personal account
and a
shared account). When I send messages from the shared account
the
message is stored in "Sent Items" of my personal account. As I
would
like these mails to be stored in the "Sent Items" of the shared
account I wrote some code to do move the sent item: (this is an
extract of the code)
Private Sub objSentItems_ItemAdd(ByVal Item As Object)
'Fired when something is added to personal "Sent Mail" folder
If TypeName(Item) = "MailItem" Then
If Item.SentOnBehalfOfName = "Shared Account" Then
Set DestinationFolder =
Application.Session.GetFolderFromID(SentEntryID, SentStoreID)
Item.Move (DestinationFolder)
End If
End If
End Sub
This works fine on my PC and one of my colleague's, however
another
colleague's PC displays the security alert ("A program is trying
to
access e-mail addresses stored in Outlook. Do you want to allow
this?").
The line that appears to be generating is "If
Item.SentOnBehalfOfName
= "Shared Account" Then".
All three PCs are Outlook 2003.
Any ideas on what could be causing this behaviour?
Many thanks
N A Cooke- Hide quoted text -
- Show quoted text -- Hide quoted text -
- Show quoted text -- Hide quoted text -

- Show quoted text -
 
N

nacooke

Hi Michael

Will do, am not in office until monday so will have to wait until
monday. Thanks a lot for your help though

Nick

Please re-check that your colleague's PC really runs OL 2003, because it
behaves like OL XP.

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
Keep your Outlook categories organized!
http://www.shareit.com/product.html?productid=300120654&languageid=1
(German:http://www.VBOffice.net/product.html?pub=6)

Am 16 Feb 2007 00:54:21 -0800 schrieb (e-mail address removed):
Here's the full code I'm using:
*********************************************************************************************************************************************

Private SentEntryID As String
Private SentStoreID As String
Private WithEvents objSentItems As Items
Private MailItem As Outlook.MailItem
Public Sub Application_Startup()
'Retrieve ID for accessing non-default sent folder
getStoreFolderID ("Mailbox - Shared Account")
Set objSentItems =
Application.Session.GetDefaultFolder(olFolderSentMail).Items
End Sub
Function getStoreFolderID(StoreName)
'Gets the Shared Account Sent Folder
Dim Store As Object
Dim StoreFolder As Object
Dim i As Integer
Set Store = Application.GetNamespace("MAPI").Folders
For Each StoreFolder In Store
If StoreFolder.Name = StoreName Then
For i = 1 To StoreFolder.Folders.Count
If StoreFolder.Folders(i).Name = "Sent Items" Then
SentEntryID = StoreFolder.Folders(i).EntryID
SentStoreID = StoreFolder.Folders(i).StoreID
Exit For
End If
Next
Exit For
End If
Next
Set Store = Nothing
Set StoreFolder = Nothing
End Function
Private Sub objSentItems_ItemAdd(ByVal Item As Object)
'Fired when something is added to personal "Sent Mail" folder
If TypeOf Item Is Outlook.MailItem Then
With Item
Set MailItem =
Application.GetNamespace("mapi").GetItemFromID(.EntryID, .Parent.StoreID)
End With
If MailItem.SenderName = "Shared Account" Then
Set DestinationFolder =
Application.Session.GetFolderFromID(SentEntryID, SentStoreID)
MailItem.Move (DestinationFolder)
End If
End If
Set MailItem = Nothing
End Sub
Not as far as I am aware. All the code does is identify which sent
folder to use (on Application startup), and then the only code is the
bits I posted earlier. I'll post the whole code tomorrow if that is
of use (am not at work now).
Thanks
Nick
Hmmm.. And you never reset the Application intrinsic variable, right?
Dmitry Streblechenko (MVP)http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

Yes, it's when accessing SentOnBehalfOfName in the original code, or
MailItem.SenderName in the code suggested by Michael. (I identified
this by stepping through the code to see which line threw the error).
Hmmm... Than it should work perfectly fine... Are you sure it is that
line?
Dmitry Streblechenko (MVP)http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

The code is in the ThisOutlookSession module in VBAProject.otm. This
has been copied and pasted into the same location on my colleagues
computers.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top