Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Outlook / Programming VBA / November 2004

Tip: Looking for answers? Try searching our database.

Move method doesn't move item

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Barney Mowder - 15 Nov 2004 21:43 GMT
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
Sue Mosher [MVP-Outlook] - 15 Nov 2004 23:42 GMT
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).

Signature

Sue Mosher, Outlook MVP
Author of
    Microsoft Outlook Programming - Jumpstart for
    Administrators, Power Users, and Developers
    http://www.outlookcode.com/jumpstart.aspx

> All-
>
[quoted text clipped - 107 lines]
>
> End Sub
Barney Mowder - 16 Nov 2004 03:01 GMT
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
Sue Mosher [MVP-Outlook] - 16 Nov 2004 12:00 GMT
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.

Signature

Sue Mosher, Outlook MVP
Author of
    Microsoft Outlook Programming - Jumpstart for
    Administrators, Power Users, and Developers
    http://www.outlookcode.com/jumpstart.aspx

> Sue-
>
[quoted text clipped - 21 lines]
>
> Barney
Barney Mowder - 16 Nov 2004 21:07 GMT
>>>>From: Barney Mowder
>>>>Date Posted: 11/15/2004 2:53:00 PM
[quoted text clipped - 53 lines]
>>>>    
>>>>    Set objRecipient =
objNameSpace.CreateRecipient("SPECIAL_ACCOUNT")
>>>>    Set objFolder =
objNameSpace.GetSharedDefaultFolder(objRecipient,
olFolderInbox).folders("ReSubject")
>>>>    
>>>>    Set objSel = objApp.ActiveExplorer.Selection
[quoted text clipped - 21 lines]
>>>>            Set objReItem = CreateObject("Redemption.SafeMailItem")
>>>>            objReItem.Item =
objOlItem.Attachments.Item(iIdx0).EmbeddedMsg
>>>>            If (objReItem.Item.Class = olMailItem) Then
>>>>              If (objReItem.SenderName = "SPECIAL_ACCOUNT") Then
[quoted text clipped - 26 lines]
>>>>    
>>>>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).

>>From: Barney Mowder
>>Date Posted: 11/15/2004 8:22:00 PM
[quoted text clipped - 21 lines]
>>
>>  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
[quoted text clipped - 6 lines]
>detail that you risk not getting the answer you're looking for. Please take
>the time to quote the original message.

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
Sue Mosher [MVP-Outlook] - 16 Nov 2004 21:16 GMT
>  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

Signature

Sue Mosher, Outlook MVP
Author of
    Microsoft Outlook Programming - Jumpstart for
    Administrators, Power Users, and Developers
    http://www.outlookcode.com/jumpstart.aspx

>>>>>From: Barney Mowder
>>>>>Date Posted: 11/15/2004 2:53:00 PM
[quoted text clipped - 189 lines]
>
> Barney
Barney Mowder - 16 Nov 2004 22:37 GMT
All-

Well, heck.  I tried to paste the past postings into the last reply, but
the site (www.developersdex.com/bv/newmessage.asp) seeems to have
decided that I've said enough, and trunc'd the reply.  Don't know a
workaround for this.  Sorry.
Sue Mosher [MVP-Outlook] - 16 Nov 2004 22:40 GMT
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?

Signature

Sue Mosher, Outlook MVP
Author of
    Microsoft Outlook Programming - Jumpstart for
    Administrators, Power Users, and Developers
    http://www.outlookcode.com/jumpstart.aspx

> All-
>
> Well, heck.  I tried to paste the past postings into the last reply, but
> the site (www.developersdex.com/bv/newmessage.asp) seeems to have
> decided that I've said enough, and trunc'd the reply.  Don't know a
> workaround for this.  Sorry.
Barney Mowder - 17 Nov 2004 00:46 GMT
>>From: Barney Mowder
>>Date Posted: 11/16/2004 3:50:00 PM
>> All-
>>
>> Well, heck. I tried to paste the past postings into the last reply,
but
>> the site (www.developersdex.com/bv/newmessage.asp) seeems to have
>> decided that I've said enough, and trunc'd the reply. Don't know a
>> workaround for this. Sorry.
>>
>>  From: Sue
Mosher [MVP-Outlook]

>From: Sue Mosher [MVP-Outlook]
>Date Posted: 11/16/2004 5:20:00 PM
[quoted text clipped - 4 lines]
>
>Did you try have a chance to what I suggested?

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
Barney Mowder - 17 Nov 2004 00:56 GMT
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
Barney Mowder - 17 Nov 2004 02:17 GMT
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
Sue Mosher [MVP-Outlook] - 17 Nov 2004 03:44 GMT
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?

Signature

Sue Mosher, Outlook MVP
Author of
    Microsoft Outlook Programming - Jumpstart for
    Administrators, Power Users, and Developers
    http://www.outlookcode.com/jumpstart.aspx

> Sue-
>
[quoted text clipped - 101 lines]
>
> Barney
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.