Method "Display" of object "mailitem" failed -2147221441 (80040107) when running code in background,

C

Carol Chisholm

Method "Display" of object "mailitem" failed -2147221441 (80040107)

I'm working on some code to allow the user to read messages press a
button to file the message according to what they see. After each
message is moves to another subfolder of the Inbox, I want to move
back to the Inbox and display the next selected item.

I am able to get my item but it some do not display unless I step
through the code in debug mode.

Here if the code:


'move to appropriate folder
Set objFolder =
objNameSpace.GetDefaultFolder(olFolderInbox).Folders(strOlFld)
objCurrItem.Move objFolder
'go back to the inbox and display next item
Set objFolder = objNameSpace.GetDefaultFolder(olFolderInbox)
Set objCurrItem = objOLApp.ActiveExplorer.Selection.Item(1)
objCurrItem.Display

Here is the error:

Method "Display" of object "mailitem" failed -2147221441 (80040107)

If I choose Debug and press F8, I get the next item to display. Any
ideas?
 
K

Ken Slovak - [MVP - Outlook]

Is the ActiveExplorer pointing at the Inbox folder? You might have to set it
using the CurrentFolder property of the Explorer object. You would set it to
a MAPIFolder object.

Also, Move is a function and I'd also check to see if the new item was
Nothing before trying to display it.
 
C

Carol Chisholm

Thanks Ken,

I spent a long time trying to sort out explorer objects with no
success. None of my books helps on this one either, if you can
recommend one I'd be interested.

Instead I used the less elegant but effective command button solution:

Dim olCmd As Office.CommandBarButton
Dim olPop As Office.CommandBarPopup
'select next message
Set olPop = Application.ActiveInspector.CommandBars.FindControl(, 360)
'next item command button
Set olCmd = olPop.Controls(1)
olCmd.Execute

'folder for processed message
Set olFolder =
olNameSpace.GetDefaultFolder(olFolderInbox).Folders(strOlFld)
'move old message to appropriate folder
itmCurrItem.Move olFolder


Carol
 
K

Ken Slovak - [MVP - Outlook]

An Inspector is only for an open item, if the item is not open there is no
ActiveInspector.

Dim oInbox As Outlook.MAPIFolder

Set oInbox = oNameSpace.GetDefaultFolder(olFolderInbox)
Set ActiveExplorer.CurrentFolder = oInbox

That would make the Inbox the folder in ActiveExplorer.
 

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