Move method doesn't move item

B

Barney Mowder

All-

NOTE: my code is posted at the BOTTOM of this message.

I'm using Outlook 2000 VBA on a Exchange 5.5 client mailbox, and I
have a situation where I am responsible for another special account
which receives mail.

I have full permissions in this special account's mailbox, and can
manually move items around from the Outlook GUI with no trouble. It
is open i my outlook sessions as a matter of course.

For reasons too complex to explain, I need to programmatically
change the subject of selected items in the special account's inbox,
and move them to a sub folder in the special account's inbox via a
macro.

The problem I'm having is that I can get a path to the sub folder,
but when I use the .Move method on a mail item, it doesn't actually
move. No error is reported, and the subject setting method works
fine. I have tried both:

objItem.Move objFolder

and

set objItem = objItem.Move(objFolder)

but they both do not work, and they both return no run-time error.
Can anyone help me with this beast? I'm running out of hair to pull
out.

Thanks, Barney.

The code I'm using is :

Sub SetSubjSID()
On Error Resume Next
Dim objApp As Application
Dim objFolder As Object
Dim objSel As Selection
Dim objItem As Object
Dim wString As String
Dim iIdx0 As Integer
Dim objNameSpace As Object
Dim objRecipient As Recipient
Dim objSafeMail As Object


Set objSafeMail = CreateObject("Redemption.SafeMailItem")
Set objApp = GetObject(, "Outlook.Application")
Set objNameSpace = objApp.GetNamespace("MAPI")

Set objRecipient = objNameSpace.CreateRecipient("SPECIAL_ACCOUNT")
Set objFolder = objNameSpace.GetSharedDefaultFolder(objRecipient,
olFolderInbox).folders("ReSubject")

Set objSel = objApp.ActiveExplorer.Selection

For Each objItem In objSel
DoEvents

If bAbort = True Then
GoTo EndSub
End If

If (objItem.Class = olReportItem) Then
wString = GetRecip(objItem)
objItem.Subject = wString
objItem.Save
ElseIf (objItem.Class = olMailItem) Then
If (objItem.Attachments.Count) Then
wString = ""
Dim Recip
Dim objOlItem As Object
Set objOlItem = CreateObject("Redemption.SafeMailItem")
objOlItem.Item = objItem
For iIdx0 = 1 To objOlItem.Item.Attachments.Count
Dim objReItem As Object
Set objReItem = CreateObject("Redemption.SafeMailItem")
objReItem.Item =
objOlItem.Attachments.Item(iIdx0).EmbeddedMsg
If (objReItem.Item.Class = olMailItem) Then
If (objReItem.SenderName = "SPECIAL_ACCOUNT") Then
For Each Recip In objReItem.Recipients
wString = Recip.Name
Next Recip
End If
End If
Set objReItem = Nothing
Next iIdx0
If (wString <> "") Then
objItem.Subject = wString
objItem.Save
Set objItem = objItem.Move(objFolder)
DoEvents
End If
Set Recip = Nothing
Set objOlItem = Nothing
End If
End If
Next
EndSub:
bAbort = False
Set objNameSpace = Nothing
Set objRecipient = Nothing
Set objItem = Nothing
Set objSel = Nothing
Set objFolder = Nothing
Set objApp = Nothing

End Sub
 
S

Sue Mosher [MVP-Outlook]

I bet if you took out the On Error Resume Next, you'd get an error that
objFolder doesn't exist. I don't think you can get a subfolder in a shared
mailbox that way. Instead, you should try walking the folder hierarchy from
the top of the mailbox down (see
http://www.outlookcode.com/d/code/getfolder.htm).

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
B

Barney Mowder

Sue-

Thanks for your time! I tried your suggestion, i.e., I removed the
'on error resume next', and modified my code from:

Set objFolder = objNameSpace.GetSharedDefaultFolder(objRecipient,
olFolderInbox).folders("ReSubject")

To:

Set objFolder = objNameSpace.GetSharedDefaultFolder(objRecipient,
olFolderInbox)
Set objFolder = objFolder.folders("ReSubject")

The code still executes without any error at all, and it stll does NOT
move the item to the spcial account's subfolder.

The wierd thing is that the folder object is definitely being found,
and with either syntax above for the objFolder assignment, Msgbox
objFolder.Name returns a message box with 'ReSubject". Go figure.

Any further thoughts? I really appreciate your spending BrainWidth on
this; it's got me barking.

Barney


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
S

Sue Mosher [MVP-Outlook]

I still think you shouldn't use use GetSharedDefaultFolder. Instead, walk
the folder hierarchy down from the top of the mailbox.

Also note: The newsgroup interface you are using apparently does not quote
earlier messages in the thread, making your latest message so short on
detail that you risk not getting the answer you're looking for. Please take
the time to quote the original message.
 
B

Barney Mowder

From: Barney Mowder
objNameSpace.GetSharedDefaultFolder(objRecipient,
olFolderInbox).folders("ReSubject")
Set objSel = objApp.ActiveExplorer.Selection

For Each objItem In objSel
DoEvents

If bAbort = True Then
GoTo EndSub
End If

If (objItem.Class = olReportItem) Then
wString = GetRecip(objItem)
objItem.Subject = wString
objItem.Save
ElseIf (objItem.Class = olMailItem) Then
If (objItem.Attachments.Count) Then
wString = ""
Dim Recip
Dim objOlItem As Object
Set objOlItem = CreateObject("Redemption.SafeMailItem")
objOlItem.Item = objItem
For iIdx0 = 1 To objOlItem.Item.Attachments.Count
Dim objReItem As Object
Set objReItem = CreateObject("Redemption.SafeMailItem")
objReItem.Item = objOlItem.Attachments.Item(iIdx0).EmbeddedMsg
If (objReItem.Item.Class = olMailItem) Then
If (objReItem.SenderName = "SPECIAL_ACCOUNT") Then
For Each Recip In objReItem.Recipients
wString = Recip.Name
Next Recip
End If
End If
Set objReItem = Nothing
Next iIdx0
If (wString <> "") Then
objItem.Subject = wString
objItem.Save
Set objItem = objItem.Move(objFolder)
DoEvents
End If
Set Recip = Nothing
Set objOlItem = Nothing
End If
End If
Next
EndSub:
bAbort = False
Set objNameSpace = Nothing
Set objRecipient = Nothing
Set objItem = Nothing
Set objSel = Nothing
Set objFolder = Nothing
Set objApp = Nothing

End Sub
From: Sue Mosher [MVP-Outlook]
Date Posted: 11/15/2004 4:58:00 PM

I bet if you took out the On Error Resume Next, you'd get an error that
objFolder doesn't exist. I don't think you can get a subfolder in a shared
mailbox that way. Instead, you should try walking the folder hierarchy from
the top of the mailbox down (see
http://www.outlookcode.com/d/code/getfolder.htm).

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
From: Barney Mowder
Date Posted: 11/15/2004 8:22:00 PM

Sue-

Thanks for your time! I tried your suggestion, i.e., I removed the
'on error resume next', and modified my code from:

Set objFolder = objNameSpace.GetSharedDefaultFolder(objRecipient,
olFolderInbox).folders("ReSubject")

To:

Set objFolder = objNameSpace.GetSharedDefaultFolder(objRecipient,
olFolderInbox)
Set objFolder = objFolder.folders("ReSubject")

The code still executes without any error at all, and it stll does NOT
move the item to the spcial account's subfolder.

The wierd thing is that the folder object is definitely being found,
and with either syntax above for the objFolder assignment, Msgbox
objFolder.Name returns a message box with 'ReSubject". Go figure.

Any further thoughts? I really appreciate your spending BrainWidth on
this; it's got me barking.

Barney
From: Sue Mosher [MVP-Outlook]
Date Posted: 11/16/2004 5:30:00 AM

I still think you shouldn't use use GetSharedDefaultFolder. Instead, walk
the folder hierarchy down from the top of the mailbox.

Also note: The newsgroup interface you are using apparently does not quote
earlier messages in the thread, making your latest message so short on
detail that you risk not getting the answer you're looking for. Please take
the time to quote the original message.

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers



news:[email protected]...

Sue-

Dang. Sorry about the trunc'd post- I did a cut & paste this time to
preserve context. Hope it helps.

I don't know of any other way to find the top of the special account's
mailbox than the GetSharedDefaultFolder method- It's not a public
folder.

See, the scenario is this: I have an Outlook session open as me
(Barney Mowder).

I have the special account's mailbox open in the same session. The
macro code I am using is native to my account. If I use
GetDefaultFolder(6), I get MY inbox.

I need an unambiguous way to point to the top of the special account's
inbox, so I can use the objFolder.Folders("ReSubject") method to point
to (walk down to) the appropriate folder.

How (if not GetSharedDefaultFolder) do I get a pointer to the top of
the special account's mailbox from MY session?

Yet again, thanks for your skull sweat. I really appreciate it.

Barney

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
S

Sue Mosher [MVP-Outlook]

How (if not GetSharedDefaultFolder) do I get a pointer to the top of
the special account's mailbox from MY session?

To get a non-default folder, you need to walk the folder hierarchy using the
Folders collections or use a function that does that for you. See
http://www.outlookcode.com/d/code/getfolder.htm

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers



Barney Mowder said:
From: Barney Mowder
Date Posted: 11/15/2004 2:53:00 PM

All-

NOTE: my code is posted at the BOTTOM of this message.

I'm using Outlook 2000 VBA on a Exchange 5.5 client mailbox, and I
have a situation where I am responsible for another special account
which receives mail.

I have full permissions in this special account's mailbox, and can
manually move items around from the Outlook GUI with no trouble. It
is open i my outlook sessions as a matter of course.

For reasons too complex to explain, I need to programmatically
change the subject of selected items in the special account's inbox,
and move them to a sub folder in the special account's inbox via a
macro.

The problem I'm having is that I can get a path to the sub folder,
but when I use the .Move method on a mail item, it doesn't actually
move. No error is reported, and the subject setting method works
fine. I have tried both:

objItem.Move objFolder

and

set objItem = objItem.Move(objFolder)

but they both do not work, and they both return no run-time error.
Can anyone help me with this beast? I'm running out of hair to pull
out.

Thanks, Barney.

The code I'm using is :

Sub SetSubjSID()
On Error Resume Next
Dim objApp As Application
Dim objFolder As Object
Dim objSel As Selection
Dim objItem As Object
Dim wString As String
Dim iIdx0 As Integer
Dim objNameSpace As Object
Dim objRecipient As Recipient
Dim objSafeMail As Object


Set objSafeMail = CreateObject("Redemption.SafeMailItem")
Set objApp = GetObject(, "Outlook.Application")
Set objNameSpace = objApp.GetNamespace("MAPI")

Set objRecipient = objNameSpace.CreateRecipient("SPECIAL_ACCOUNT")
Set objFolder =
objNameSpace.GetSharedDefaultFolder(objRecipient,
olFolderInbox).folders("ReSubject")
Set objSel = objApp.ActiveExplorer.Selection

For Each objItem In objSel
DoEvents

If bAbort = True Then
GoTo EndSub
End If

If (objItem.Class = olReportItem) Then
wString = GetRecip(objItem)
objItem.Subject = wString
objItem.Save
ElseIf (objItem.Class = olMailItem) Then
If (objItem.Attachments.Count) Then
wString = ""
Dim Recip
Dim objOlItem As Object
Set objOlItem = CreateObject("Redemption.SafeMailItem")
objOlItem.Item = objItem
For iIdx0 = 1 To objOlItem.Item.Attachments.Count
Dim objReItem As Object
Set objReItem = CreateObject("Redemption.SafeMailItem")
objReItem.Item = objOlItem.Attachments.Item(iIdx0).EmbeddedMsg
If (objReItem.Item.Class = olMailItem) Then
If (objReItem.SenderName = "SPECIAL_ACCOUNT") Then
For Each Recip In objReItem.Recipients
wString = Recip.Name
Next Recip
End If
End If
Set objReItem = Nothing
Next iIdx0
If (wString <> "") Then
objItem.Subject = wString
objItem.Save
Set objItem = objItem.Move(objFolder)
DoEvents
End If
Set Recip = Nothing
Set objOlItem = Nothing
End If
End If
Next
EndSub:
bAbort = False
Set objNameSpace = Nothing
Set objRecipient = Nothing
Set objItem = Nothing
Set objSel = Nothing
Set objFolder = Nothing
Set objApp = Nothing

End Sub
From: Sue Mosher [MVP-Outlook]
Date Posted: 11/15/2004 4:58:00 PM

I bet if you took out the On Error Resume Next, you'd get an error that
objFolder doesn't exist. I don't think you can get a subfolder in a shared
mailbox that way. Instead, you should try walking the folder hierarchy from
the top of the mailbox down (see
http://www.outlookcode.com/d/code/getfolder.htm).

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers



From: Barney Mowder
Date Posted: 11/15/2004 8:22:00 PM

Sue-

Thanks for your time! I tried your suggestion, i.e., I removed the
'on error resume next', and modified my code from:

Set objFolder = objNameSpace.GetSharedDefaultFolder(objRecipient,
olFolderInbox).folders("ReSubject")

To:

Set objFolder = objNameSpace.GetSharedDefaultFolder(objRecipient,
olFolderInbox)
Set objFolder = objFolder.folders("ReSubject")

The code still executes without any error at all, and it stll does NOT
move the item to the spcial account's subfolder.

The wierd thing is that the folder object is definitely being found,
and with either syntax above for the objFolder assignment, Msgbox
objFolder.Name returns a message box with 'ReSubject". Go figure.

Any further thoughts? I really appreciate your spending BrainWidth on
this; it's got me barking.

Barney
From: Sue Mosher [MVP-Outlook]
Date Posted: 11/16/2004 5:30:00 AM

I still think you shouldn't use use GetSharedDefaultFolder. Instead, walk
the folder hierarchy down from the top of the mailbox.

news:[email protected]...

Sue-

Dang. Sorry about the trunc'd post- I did a cut & paste this time to
preserve context. Hope it helps.

I don't know of any other way to find the top of the special account's
mailbox than the GetSharedDefaultFolder method- It's not a public
folder.

See, the scenario is this: I have an Outlook session open as me
(Barney Mowder).

I have the special account's mailbox open in the same session. The
macro code I am using is native to my account. If I use
GetDefaultFolder(6), I get MY inbox.

I need an unambiguous way to point to the top of the special account's
inbox, so I can use the objFolder.Folders("ReSubject") method to point
to (walk down to) the appropriate folder.

How (if not GetSharedDefaultFolder) do I get a pointer to the top of
the special account's mailbox from MY session?

Yet again, thanks for your skull sweat. I really appreciate it.

Barney

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
S

Sue Mosher [MVP-Outlook]

The key thing is to keep enough info in your latest post so someone just
getting into the conversation can understand it. In other words, just the
latest code snippets, for example, not everything.

Did you try have a chance to what I suggested?
 
B

Barney Mowder

From: Barney MowderMosher [MVP-Outlook]
From: Sue Mosher [MVP-Outlook]
Date Posted: 11/16/2004 5:20:00 PM

The key thing is to keep enough info in your latest post so someone just
getting into the conversation can understand it. In other words, just the
latest code snippets, for example, not everything.

Did you try have a chance to what I suggested?

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers

Sue-

I haven't tried your suggestion because I can't figure out HOW to get
to the head of the special account's mailbox.

I looked at your code sample, but it doesn't seem to apply to the
present scenario (though I have been wrong before).

The situation is this: The special account's mailbox is not public.
It is a separate mailbox. I have an outlook session which is logged in
under my username, and I have the special account's mailbox open in that
session. The macros are to run from my account.

I thought GetSharedDefaultFolder WAS the way to reference the special
account's mail box. If I use GetDefaultFolder(6), it returns a pointer
to MY Inbox, but I need to get to the special account's inbox.

Does any of this make sense? If I seem confused, it's because I am.

Thank you again for your extreme patience,

Barney




*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
B

Barney Mowder

Sue-

Whu is that the obvious never strikes you until AFTER you hit the send
key? Never mind my last post. I DO see the poing, and I'll lrt you
know how it works out. Again, Many, many thanks.

Barney



*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
B

Barney Mowder

Sue-

I took your suggestion.

I swiped the GetFolder function verbatim from
http://www.outlookcode.com/d/code/getfolder.htm) to eliminate
variability in outcome, and tested the function against items in my own
mailbox, and it works like a champ. NICE code.

Having done that, I changed my macro code to take advantage of
GetFolder, as below:

========================== snip ==========================

Sub SetSubjSID()
Dim objApp As Application
Dim objFolder As Object
Dim objSel As Selection
Dim objItem As Object
Dim wString As String
Dim iIdx0 As Integer
Dim objSafeMail As Object


Set objSafeMail = CreateObject("Redemption.SafeMailItem")
Set objApp = GetObject(, "Outlook.Application")

'All the objFolder assignment is replaced by a single call ot GetFolder

Set objFolder = GetFolder("Mailbox -
SPECIAL_ACCOUNT\Inbox\ReSubject")

'testing the returned folder value
MsgBox objFolder.Name

'it returns "ReSubject"


Set objSel = objApp.ActiveExplorer.Selection

For Each objItem In objSel
DoEvents

If bAbort = True Then
GoTo EndSub
End If

If (objItem.Class = olReportItem) Then
wString = GetRecip(objItem)
objItem.Subject = wString
objItem.Save
ElseIf (objItem.Class = olMailItem) Then
If (objItem.Attachments.Count) Then
wString = ""
Dim Recip
Dim objOlItem As Object
Set objOlItem = CreateObject("Redemption.SafeMailItem")
objOlItem.Item = objItem
For iIdx0 = 1 To objOlItem.Item.Attachments.Count
Dim objReItem As Object
Set objReItem = CreateObject("Redemption.SafeMailItem")
objReItem.Item =
objOlItem.Attachments.Item(iIdx0).EmbeddedMsg
If (objReItem.Item.Class = olMailItem) Then
If (objReItem.SenderName = "SPECIAL_ACCOUNT") Then
For Each Recip In objReItem.Recipients
wString = Recip.Name
Next Recip
End If
End If
Set objReItem = Nothing
Next iIdx0
If (wString <> "") Then
objItem.Subject = wString
objItem.Save
Set objItem = objItem.Move(objFolder)
DoEvents
End If
Set Recip = Nothing
Set objOlItem = Nothing
End If
End If
Next
EndSub:
bAbort = False
Set objItem = Nothing
Set objSel = Nothing
Set objFolder = Nothing
Set objApp = Nothing

End Sub

========================== snip ==========================


Result:

The Msgbox test displays "ReSubject". The correct folder is being
returned.

The objItem.Move(ObjFolder) call returns not a quibble about the moce
request.

It still does NOT move the item to the "ReSubject" folder.

What's the next thing I'd try if I were you?

Barney

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
S

Sue Mosher [MVP-Outlook]

Well, at least we can be more certain that you have a folder there. Have you
checked permissions on the target folder? What happens if you simplify it
down to

For Each objItem In objSel
Set objMovedItem = objItem.Move(objFolder)
Next

just for the sake of experiment?

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 

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