This is a follow-up to my earlier post
about listing and opening selected MailItems from a userform listbox. I
can generate the array containing the EntryID and StoreID of each MailItem that
meets the search criteria, but then cannot seem to use those same EntryID and
StoreID to open the mail item from the listbox. This is the first time
I've worked with the EntryID and StoreID properties, so I've missed something
important about their propor use.
In my code module ("modMain") I have this
code to search for mail items within a hierarchy of custom mail folders.
The code stores, in a global array, the StoreID of the folder containing
the found mail item, the EntryID of the item, and the formatted date it was
received. Once searching is complete, the code opens a userform to display
only the formatted dates of the found mail items in a listbox. Selecting
one of these dates and clicking on the command button "cmdOpenItem" should then
open the selected mail item and select the search string within it.
Instead, I get a run-time error of:
"The operation failed." at the GetItemFromID function call. The actual
error number reported is a very long number followed by what looks like a
hex-based number in brackets. These numbers then change each time I click
"debug" and try to run the offending GetItemFromID function. As far as I
can tell the correct EntryID and StoreID properties are being transferred from
the array to the GetItemFromID function. Why would the function choke on
them?
Sub SearchFolder
[snip]
For Each olFolder In
fldRoot.Folders
strStoreID =
olFolder.StoreID
For Each olMail
In olFolder.Items
' Convert
the mail item to a string before
searching
strMailBody =
CStr(olMail.Body)
If InStr(1, strMailBody, astrPTSTitle, vbTextCompare) > 0
Then
strMailID =
olMail.EntryID
ReDim Preserve avarFoundItems(2,
i)
avarFoundItems(0, i) =
strMailID
avarFoundItems(1, i) =
strStoreID
avarFoundItems(2, i) = Format(olMail.ReceivedTime, "Long
Date")
i = i + 1
End If
Next
olMail
Next olFolder
[snip]
With
frmResultList.lstFoundItems
.ColumnCount = 3
.Column() =
avarFoundItems
.ColumnWidths =
"0;0;-1"
End With
frmResultList.Show
End Sub
Then, from a command button on
userform frmResultList, I run this code:
Private Sub
cmdOpenItem_Click()
Dim itmMail As
Outlook.MailItem
Dim i As Integer
Dim n As Integer
If
lstFoundItems.ListIndex >= 0
Then
i =
lstFoundItems.ListIndex
Set
itmMail = gnspNameSpace.GetItemFromID(
_
modMain.avarFoundItems(i, 0),
_
modMain.avarFoundItems(i, 1))
itmMail.Display
[snip]
End Sub
thanks for reading,
Terry