Problem moving a message to another folder

F

Frank Perugini

In my VB6 addin for Outlook 2003 in IMO mode, some code that had been
running for sometime now just surfaced a problem:

A section of code that moves messages from one folder to another in a
loop is getting stuck moving one particular message. I get the
following runtime error:

-1318043643 (An unsent message cannot be flagged complete.)

The only thing different with this message is that it was flagged for
follow-up, and the follow-up was marked completed.

The code just performs the following call where all objects are valid,
and the destination entry and store id's are valid:

item.Move objNS.GetFolderFromID(strDstEntryID, strDstStoreID)

Does anyone have any idea what is happening?

Thanks,

-Frank
 
F

Frank Perugini

Forgot to mention, if I turn flag for follow-up back on for this message, it works.
 
K

Ken Slovak - [MVP - Outlook]

I'm not sure about the limitation of not being able to move an unsent
flagged item marked complete but if that's the case you could always
clear the flag before you move the item.

Move is a function that returns a new item. See if writing your code
that way helps, if not you may just have to clear the flag before you
move the item.
 
F

Frank Perugini

Ken,

Thanks for the quick response.

The follow-up flag is already cleared. This is when the problem
occurs. If I turn the flag back on, it moves with no error.

I don't want to turn the flag back on (for obvious reasons). It sounds
like a bug. I have only experienced it with Outlook 2003 so far. I
have yet to test prior versions.

-Frank
 
K

Ken Slovak - [MVP - Outlook]

Can you provide me with the code you're using and a complete
description of your setup (version, patches, OS, email setups) here in
this thread? I'll test and see if I can verify this and submit it as a
bug to MS. They are working on Outlook 2003 SP1 at this time so maybe
if it's reproducible we can get it included in SP1 or at least get it
on the list for a possible hotfix.
 
F

Frank Perugini

Ken Slovak - said:
Can you provide me with the code you're using and a complete
description of your setup (version, patches, OS, email setups) here in
this thread? I'll test and see if I can verify this and submit it as a
bug to MS. They are working on Outlook 2003 SP1 at this time so maybe
if it's reproducible we can get it included in SP1 or at least get it
on the list for a possible hotfix.

Ken,

I mocked up a quick VB app to demonstrate the problem. Add the form
below to a VB EXE project.

When you run it, it will allow you to choose a source folder, and a
destination folder. When you click the Go button, it will move all
read messages from source to destination folder.

You can make a couple of test folders in your message store to test
with. Place some messages in the source, and run it to make sure it
works.

Now, to recreate the bug, just pick a message in the destination
folder and flag it for follow-up (I also added a reminder), then mark
it as completed. Reverse the source and dest folders on the program
and click Go again.

You should see the problem.

Regards,

-Frank

------------------------------------------------------------------------------

VERSION 5.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 2715
ClientLeft = 60
ClientTop = 345
ClientWidth = 5400
LinkTopic = "Form1"
ScaleHeight = 2715
ScaleWidth = 5400
StartUpPosition = 3 'Windows Default
Begin VB.CommandButton btnGo
Caption = "Go"
Height = 375
Left = 2160
TabIndex = 7
Top = 2100
Width = 1035
End
Begin VB.TextBox txtDstFolder
Height = 315
Left = 1560
Locked = -1 'True
TabIndex = 4
Top = 1140
Width = 2535
End
Begin VB.CommandButton btnDstFolderBrowse
Caption = "Browse..."
Height = 375
Left = 4200
TabIndex = 3
Top = 1140
Width = 1035
End
Begin VB.CommandButton btnSrcFolderBrowse
Caption = "Browse..."
Height = 375
Left = 4200
TabIndex = 1
Top = 600
Width = 1035
End
Begin VB.TextBox txtSrcFolder
Height = 315
Left = 1560
Locked = -1 'True
TabIndex = 0
Top = 600
Width = 2535
End
Begin VB.Label Label3
Caption = "Move all Read mail messages from source
folder to destination folder"
Height = 315
Left = 180
TabIndex = 6
Top = 120
Width = 5055
End
Begin VB.Label Label2
Alignment = 1 'Right Justify
Caption = "Destination Folder:"
Height = 315
Left = 120
TabIndex = 5
Top = 1200
Width = 1395
End
Begin VB.Label Label1
Alignment = 1 'Right Justify
Caption = "Source Folder:"
Height = 315
Left = 120
TabIndex = 2
Top = 660
Width = 1395
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Private objApp As Outlook.Application
Private objNS As Outlook.NameSpace
Private strSrcEntryId As String
Private strSrcStoreId As String
Private strDstEntryId As String
Private strDstStoreId As String


Private Sub btnGo_Click()

Dim item As Outlook.MailItem
Dim olSrcFolder As Outlook.MAPIFolder
Dim ReadItems As Items

On Error GoTo btnGo_Click_Error

Set olSrcFolder = objNS.GetFolderFromID(strSrcEntryId,
strSrcStoreId)
Set ReadItems = olSrcFolder.Items
Set item = ReadItems.Find("[Unread] = false")

Do While Not (item Is Nothing)

item.Move objNS.GetFolderFromID(strDstEntryId, strDstStoreId)
Set item = ReadItems.FindNext

Loop


Set item = Nothing
Set ReadItems = Nothing
Set olSrcFolder = Nothing

On Error GoTo 0
Exit Sub

btnGo_Click_Error:

MsgBox "Error " & Err.Number & " (" & Err.Description & ") in
procedure btnGo_Click of Form Form1"

End Sub

Private Sub btnSrcFolderBrowse_Click()
On Error Resume Next

Dim olFolder As Outlook.MAPIFolder
Set olFolder = objNS.PickFolder
If Not IsNull(olFolder) Then
txtSrcFolder.Text = olFolder.Name
strSrcEntryId = olFolder.EntryID
strSrcStoreId = olFolder.StoreID
End If
Set olFolder = Nothing

End Sub

Private Sub btnDstFolderBrowse_Click()
On Error Resume Next

Dim olFolder As Outlook.MAPIFolder
Set olFolder = objNS.PickFolder
If Not IsNull(olFolder) Then
txtDstFolder.Text = olFolder.Name
strDstEntryId = olFolder.EntryID
strDstStoreId = olFolder.StoreID
End If
Set olFolder = Nothing
End Sub

Private Sub Form_Load()
Set objApp = CreateObject("Outlook.application")
Set objNS = objApp.GetNamespace("MAPI")
End Sub

Private Sub Form_Unload(Cancel As Integer)
Set objApp = Nothing
Set objNS = Nothing
End Sub
 
F

Frank Perugini

Ken,

I posted some code in my last reply, but forgot to describe my environment.

WinXP SP1
Office 2003 (Build 5608) in IMO Mode
Office 2003 Critical Update: KB828041
Outlook 2003 Junk E-mail Filter Update: KB832333


-Frank
 
K

Ken Slovak - [MVP - Outlook]

OK, thanks. I'll try to test it out today or over the weekend.

One quick question, you mentioned setting a flag and a reminder, was
this a QuickFlag and if so what color or did you experiment with
various colors (and also reminder times)?
 
F

Frank Perugini

Yes it was a QuickFlag set to color red. I also added a reminder at an
arbitrary time two days in the future and a time of 5:00 PM.

Let me know if you need anything further.

-Frank
 
S

Scott Emick

I am having the same problem, I cannot move items with a quickflag set
(complete). Did you find a resolution for this?

Thanks,

Scott Emick
(e-mail address removed)-sys.com
(if it's not spam, just remove the 'ham.'
 
F

Frank Perugini

Scott,

I have not found a solution yet. Ken Slovak was going to try to
confirm that it is a bug and report it to Microsoft. I posted some
code in this thread to test and debug the problem.

I have also tried using Redemption SafeMailItem.move() with the same
results.

As a workaround, I was thinking of setting the Quickflag before the
move, then clearing it after the move for messages of this type, but I
really don't like this solution.

Maybe there is there a way to move a message with a different
programming interface other than OOM. Maybe CDO or Extended MAPI, and
would these interfaces suffer the same problem?

-Frank
 
K

Ken Slovak - [MVP - Outlook]

I verified the bug and it appears with even simpler code than you sent
me. Even in an unrestricted Items collection (no filter on UnRead) you
get the same error in a simple count down For loop.

You don't get an errror if you use CDO 1.21 to do the move however, so
that's a workaround.

I reported the bug to MS and escalated it. We'll see if and when it's
fixed.

Here is a modification of the move button click procedure that worked
using CDO 1.21. That's an optional installation for Outlook 2000 and
later, so it must be installed and referenced in your project for this
code to work.

Private Sub btnGo_Click()
Dim olSrcFolder As Outlook.MAPIFolder
Dim oDummy As MAPI.Message
Dim oCDO As MAPI.Session
Dim oMessages As MAPI.Messages
Dim oMessage As MAPI.Message
Dim oSFolder As MAPI.Folder
Dim oDFolder As MAPI.Folder
Dim lCount As Long
Dim i As Long

On Error GoTo btnGo_Click_Error

Set oCDO = CreateObject("MAPI.Session")
oCDO.Logon "", "", False, False

Set olSrcFolder = objNS.GetFolderFromID(strSrcEntryId,
strSrcStoreId)
Set oSFolder = oCDO.GetFolder(olSrcFolder.EntryID,
olSrcFolder.StoreID)
Set oMessages = oSFolder.Messages

lCount = oMessages.Count
For i = lCount To 1 Step -1
Set oMessage = oMessages.item(i)
Set oDummy = oMessage.MoveTo(strDstEntryId, strDstStoreId)
Next i

oCDO.Logoff

Set oDummy = Nothing
Set olSrcFolder = Nothing
Set oCDO = Nothing
Set oMessages = Nothing
Set oMessage = Nothing
Set oSFolder = Nothing
Set oDFolder = Nothing

On Error GoTo 0
Exit Sub

btnGo_Click_Error:
MsgBox "Error " & Err.Number & _
" (" & Err.Description & ") in procedure btnGo_Click of Form
Form1"
End Sub
 
S

Scott Emick

Frank,

What I did was simply leave the messages which are flagged as
needing something done in my inbox, and removing flag from completed
items. So it would follow that I could remove any flags, record them,
move the item and re-apply in the destination folder.

I am not sure if Extended MAPI could move something, I don't know
anything about it. CDO I don't think is capable, but it would
certainly be interesting to investigate both options.

Thanks for the update, I have been aware of this bug for some time,
probably > 6 months I would say.

Scott
 
F

Frank Perugini

Scott,

Ken just posted code to move messages using CDO. It does not suffer
the flag bug. However, I don't want to require CDO.DLL with my Add-in,
so I have been investigating an alternative with extended MAPI using:

IMAPIFolder::CopyMessages() with MESSAGE_MOVE flag set.

I'm not even sure that it will not suffer the same bug yet.

I started with the solution of manipulating the flags with OOM before
the move, then I was going to restore them after the move, but you
loose the item's EntryID after the move (it changes), so that posed
further complications.

So CDO is an easy work around, Extended MAPI is going to require a C++
DLL (if it works), and OOM is going to require manipulating and
restoring flags with the restoring requiring following up in the
destination folder with some kind of search to find the moved
MailItems.

Maybe Dmitry can solve this problem in his Outlook Redemption DLL.
Hope he is reading this ;)

Regards,

-Frank
 
K

Ken Slovak - [MVP - Outlook]

So far it looks like only CDO 1.21 or Extended MAPI would be a
workaround directly. You could try SafeMailItem.CopyTo and then delete
the original item in Redemption too.

I end up having to use CDO in many of my COM addins, there's just too
much missing from the Outlook Object Model and Redemption doesn't yet
have things like InfoStores. You can demand install CDO if you need
to, the user needs access to the Office CD or network installation
point however. The ItemsCB sample at www.microeye.com shows how to do
a demand installation of CDO.
 

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