tags:

views:

781

answers:

5

Hi.

I use a macro in outlook 2003 to move selected emails to a specific folder. The moving works, but unfortunately the received date is overwritten to the current time. Any idea on how to prevent this.

I use this code:

Sub verschiebenInOrdner()

On Error Resume Next

    Dim objFolder As Outlook.MAPIFolder, objInbox As Outlook.MAPIFolder
    Dim objNS As Outlook.NameSpace, objItem As Outlook.MailItem

    Set objNS = Application.GetNamespace("MAPI")
    Set objInbox = objNS.GetDefaultFolder(olFolderInbox)

    Set objFolder = objNS.Folders.Item("2009").Folders.Item("In")

    If objFolder Is Nothing Then
        MsgBox "This folder doesn't exist!", vbOKOnly + vbExclamation, "INVALID FOLDER"
    End If

    If Application.ActiveExplorer.Selection.Count = 0 Then
        Exit Sub
    End If

    For Each objItem In Application.ActiveExplorer.Selection
        If objFolder.DefaultItemType = olMailItem Then
            If objItem.Class = olMail Then
                objItem.UnRead = False
                objItem.Move objFolder
            End If
        End If
    Next

    Set objItem = Nothing
    Set objFolder = Nothing
    Set objInbox = Nothing
    Set objNS = Nothing
End Sub

Thanks to the help of 76mel I came up with this:

    Sub verschiebenInArchiv()

Dim Session As Redemption.rDOSession
Dim objFolder As Redemption.RDOFolder
Dim objItem As Outlook.MailItem
Dim objItem2 As Redemption.RDOMail

Set Session = CreateObject("Redemption.RDOSession")

Session.Logon

Set objFolder = Session.Stores.Item("2009").IPMRootFolder.Folders("In")

If Application.ActiveExplorer.Selection.Count = 0 Then
    Exit Sub
End If

For Each objItem In Application.ActiveExplorer.Selection
    Set objItem2 = Session.GetMessageFromID(objItem.EntryID, Session.Stores.DefaultStore.EntryID)
    objItem2.Move objFolder
Next

End Sub

This works when I am in my Inbox. Does anybody know how I can set the Store-ID in GetMessageFromID to the ID of the store in which my selection is made?

Edit: Thanks 76mel, I am using objItem.Parent.StoreID now to get the current StoreID.

A: 

It doesn't change the date for me in Outlook 2003 either. If it is a continuing problem for you I would try to get the date of the item and overwrite it after transferring it.

mandroid
the date is read only and can't be set by code
computhomas
+1  A: 

Your right there has been a few reports around the net saying it doesn’t work.

It would seem that VB6 doesn’t bubble up an error :( . I think that the way to tackle this would be to use CDO or the defacto 3rd party lib "Redemption". To do the actual move in the background.

M

Update: Try something like this .. I dont have VB on may machine so haven't tested it But you will get the idea.

Sub verschiebenInOrdner()

On Error Resume Next


    Dim objNS As Outlook.NameSpace
    Dim objRDOSession As Redemption.RDOSession
    Dim objRDOFolder As Redemption.RDOFolder
    Dim objItem As Outlook.MailItem
    Dim objRDOMail As Redemption.RDOMail


    Set objNS = Application.GetNamespace("MAPI")
    Set objRDOSession = CreateObject("Redemption.RDOSession")
    objRDOSession.MAPIOBJECT = objNS.MAPIOBJECT  'or Logon

    Set objRDOFolder = Session.GetFolderFromPath("<YOUR PATH>")
    ' do your validation for folder and selection



    For Each objItem In Application.ActiveExplorer.Selection
        If objFolder.DefaultItemType = olMailItem Then
            If objItem.Class = olMail Then
              Set objRDOMail = objRDOSession.GetMessageFromID(objItem.EntryID)
              objRDOMail.UnRead = False
              objRDOMail.Move objRDOFolder

            End If
        End If
    Next



    Set objItem = Nothing
    Set objRDOMail = Nothing
    Set objRDOFolder = Nothing
    Set objRDOSession = Nothing
    Set objNS = Nothing
End Sub
76mel
I tried copying the mail to a Redemption.SafeMailItem and move this afterwards, but it still overwrites the ReceivedTime.
computhomas
Ok Safemail work a the same level as the OOM so probably experience the same problem. I would use RDO if you are using Redemption.Create a RDOSession >Logon >grab your folder using GetFolderFromPath and the use the entryids from you selection to get RDOMail via the session using GetMessageFromID. Then do you move on the RDOMail.
76mel
Thank you very much, just one little detail. Please see my edit in the question.
computhomas
A: 

Hi i have the same problem here with Outlook 2003 SP3

after Moving the mail with the .move command the received date in the overview will get the new date, but if you are opening the mail itself you see the correct date and time.

are there any news how to solve this issue ?

Hi FeZ, see the update in the question and the answer by 76mel.
computhomas
A: 

I found the solution : in the sub folder you move the email to, simply add a column for the field "date created" instead of "received date" and sort using this field... job done !

Reef

Reef25
A: 

Reef's solution is so simple it should be moved to the top of this thread...

neamo