Options for finding and listing MailItems 
Author Message
 Options for finding and listing MailItems

I'm working on an Outlook 2000 VBA project which will search a hierarchy of
custom folders for e-mails containing user-specified text strings and
display a list of items found.  As someone who's not done any VBA with
Outlook I'm hoping to get some pointers on the best approach to this.

What I've done so far is code the folder search loop and store the EntryID,
StoreID, and CreationDate properties of each found MailItem into a 2-dim
String array.  Is this the most efficient way to do this?

    Dim avarFoundItems() As Variant

    n = 0
    ' Search through sub-folders with names for years, i.e. "1999", "2000",
"2001", and so on
    For Each fldTransaction In
gfldMailbox.Folders("Operations").Folders("PTS").Folders("Transactions").Fol
ders
        strStoreID = fldTransaction.StoreID
        For Each olMail In fldTransaction.Items

            ' Convert the mail item to a string before searching
            strMailBody = CStr(olMail.Body)
            If InStr(1, strMailBody, strTitle, vbTextCompare) > 0 Then
                strMailID = olMail.EntryID
                ReDim avarFoundItems(n, 1)
                avarFoundItems(n, 0) = n + 1
                avarFoundItems(n, 1) = strMailID
                avarFoundItems(n, 2) = strStoreID
                avarFoundItems(n, 3) = Format(olMail.CreationTime, "Long
Date")
                n = n + 1
            End If
        Next olMail
    Next fldTransaction

After the search is complete, I'd like to display a ListBox with, say, the
folder name and the MailItem.CreationDate which will allow the user to
select and open one of the found MailItems.  Trouble is, I don't want to
display the EntryID and StoreID in the dialog, but I _would_ like to use
them to find and open a selected MailItem once the user double-clicks an
item on the list.  It appears that if I populate the ListBox with the List()
method, all the elements in my array will be displayed in the ListBox.  Can
the elements be restricted to just a few without losing the convenience of
the List() method?  If not, what other means are available for populating
the ListBox?

Any suggestions for how to deal with this "problem" would be greatly
appreciated.

Thanks for reading,
Terry



Sun, 03 Jul 2005 07:32:47 GMT  
 Options for finding and listing MailItems
I use similar methods all the time. You just need to set the list box to display only one column -- set that column's width (and the one for the date) to whatever you want, then set the columns for the entryID and storeID to 0 width.

--
Sue Mosher, Outlook MVP
Outlook and Exchange solutions at http://www.slipstick.com
Author of
     Microsoft Outlook Programming: Jumpstart
     for Administrators, Power Users, and Developers
     http://www.slipstick.com/books/jumpstart.htm

Quote:

> After the search is complete, I'd like to display a ListBox with, say, the
> folder name and the MailItem.CreationDate which will allow the user to
> select and open one of the found MailItems.  Trouble is, I don't want to
> display the EntryID and StoreID in the dialog, but I _would_ like to use
> them to find and open a selected MailItem once the user double-clicks an
> item on the list.  It appears that if I populate the ListBox with the List()
> method, all the elements in my array will be displayed in the ListBox.  Can
> the elements be restricted to just a few without losing the convenience of
> the List() method?  If not, what other means are available for populating
> the ListBox?



Sun, 03 Jul 2005 21:40:46 GMT  
 Options for finding and listing MailItems
Thanks Sue,

I'll give it a spin.

Terry



I use similar methods all the time. You just need to set the list box to
display only one column -- set that column's width (and the one for the
date) to whatever you want, then set the columns for the entryID and storeID
to 0 width.

--
Sue Mosher, Outlook MVP
Outlook and Exchange solutions at http://www.slipstick.com
Author of
     Microsoft Outlook Programming: Jumpstart
     for Administrators, Power Users, and Developers
     http://www.slipstick.com/books/jumpstart.htm


Quote:

> After the search is complete, I'd like to display a ListBox with, say, the
> folder name and the MailItem.CreationDate which will allow the user to
> select and open one of the found MailItems.  Trouble is, I don't want to
> display the EntryID and StoreID in the dialog, but I _would_ like to use
> them to find and open a selected MailItem once the user double-clicks an
> item on the list.  It appears that if I populate the ListBox with the
List()
> method, all the elements in my array will be displayed in the ListBox.
Can
> the elements be restricted to just a few without losing the convenience of
> the List() method?  If not, what other means are available for populating
> the ListBox?



Sun, 03 Jul 2005 23:32:58 GMT  
 Options for finding and listing MailItems
I came up with the following code to a listbox using the List() function,
but the first element of the list is blank.  Any idea why this should be and
how to get all rows from the array displayed?  In single-step mode, the
array is populated correctly.

Private Sub UserForm_Initialize()

    With lstFoundItems
        .ColumnCount = 3
        .List() = avarFoundItems
        .ColumnWidths = "0;0;-1"
    End With

End Sub

Thanks again,
Terry



I use similar methods all the time. You just need to set the list box to
display only one column -- set that column's width (and the one for the
date) to whatever you want, then set the columns for the entryID and storeID
to 0 width.

--
Sue Mosher, Outlook MVP
Outlook and Exchange solutions at http://www.slipstick.com
Author of
     Microsoft Outlook Programming: Jumpstart
     for Administrators, Power Users, and Developers
     http://www.slipstick.com/books/jumpstart.htm


Quote:

> After the search is complete, I'd like to display a ListBox with, say, the
> folder name and the MailItem.CreationDate which will allow the user to
> select and open one of the found MailItems.  Trouble is, I don't want to
> display the EntryID and StoreID in the dialog, but I _would_ like to use
> them to find and open a selected MailItem once the user double-clicks an
> item on the list.  It appears that if I populate the ListBox with the
List()
> method, all the elements in my array will be displayed in the ListBox.
Can
> the elements be restricted to just a few without losing the convenience of
> the List() method?  If not, what other means are available for populating
> the ListBox?



Mon, 04 Jul 2005 02:19:17 GMT  
 Options for finding and listing MailItems

I think arrays default to zero-based -- do you have a 0,0 element that's blank?

Quote:

> I came up with the following code to a listbox using the List() function,
> but the first element of the list is blank.  Any idea why this should be and
> how to get all rows from the array displayed?  In single-step mode, the
> array is populated correctly.

> Private Sub UserForm_Initialize()

>     With lstFoundItems
>         .ColumnCount = 3
>         .List() = avarFoundItems
>         .ColumnWidths = "0;0;-1"
>     End With

> End Sub

> Thanks again,
> Terry



> I use similar methods all the time. You just need to set the list box to
> display only one column -- set that column's width (and the one for the
> date) to whatever you want, then set the columns for the entryID and storeID
> to 0 width.



> > After the search is complete, I'd like to display a ListBox with, say, the
> > folder name and the MailItem.CreationDate which will allow the user to
> > select and open one of the found MailItems.  Trouble is, I don't want to
> > display the EntryID and StoreID in the dialog, but I _would_ like to use
> > them to find and open a selected MailItem once the user double-clicks an
> > item on the list.  It appears that if I populate the ListBox with the
> List()
> > method, all the elements in my array will be displayed in the ListBox.
> Can
> > the elements be restricted to just a few without losing the convenience of
> > the List() method?  If not, what other means are available for populating
> > the ListBox?



Mon, 04 Jul 2005 04:40:00 GMT  
 Options for finding and listing MailItems

No, I just neglected to use the Preserve statement when I Redim'd my array at the start of my search loop.  Once I corrected that, however, I realized I couldn't simply add a new row to my array each time the search found a matching mailitem.  Only the last dimension can be changed.  So, if my array of found items looks like this:

    EntryID    StoreID    ReceivedTime
    EntryID    StoreID    ReceivedTime
    EntryID    StoreID    ReceivedTime
    [and so on]

the first dimension (rows) have to be incremented for each successful search.  To use ReDim, though, I would have to have an array like this:

    EntryID        EntryID        EntryID
    StoreID        StoreID        StoreID
    ReceivedTime   ReceivedTime   ReceivedTime

which of course throws the listbox into chaos.

Is there an "easy" way out of this dilemma?

Thanks again for reading,

Terry


I think arrays default to zero-based -- do you have a 0,0 element that's blank?

Quote:

> I came up with the following code to a listbox using the List() function,
> but the first element of the list is blank.  Any idea why this should be and
> how to get all rows from the array displayed?  In single-step mode, the
> array is populated correctly.

> Private Sub UserForm_Initialize()

>     With lstFoundItems
>         .ColumnCount = 3
>         .List() = avarFoundItems
>         .ColumnWidths = "0;0;-1"
>     End With

> End Sub

> Thanks again,
> Terry



> I use similar methods all the time. You just need to set the list box to
> display only one column -- set that column's width (and the one for the
> date) to whatever you want, then set the columns for the entryID and storeID
> to 0 width.



> > After the search is complete, I'd like to display a ListBox with, say, the
> > folder name and the MailItem.CreationDate which will allow the user to
> > select and open one of the found MailItems.  Trouble is, I don't want to
> > display the EntryID and StoreID in the dialog, but I _would_ like to use
> > them to find and open a selected MailItem once the user double-clicks an
> > item on the list.  It appears that if I populate the ListBox with the
> List()
> > method, all the elements in my array will be displayed in the ListBox.
> Can
> > the elements be restricted to just a few without losing the convenience of
> > the List() method?  If not, what other means are available for populating
> > the ListBox?



Mon, 04 Jul 2005 05:49:03 GMT  
 Options for finding and listing MailItems
Ahhh.  I just discovered the Column() function will do the transposition of
rows and columns that will allow me to use the ReDim Preserve statement.
Whew.

Thanks, Sue.


No, I just neglected to use the Preserve statement when I Redim'd my array
at the start of my search loop.  Once I corrected that, however, I realized
I couldn't simply add a new row to my array each time the search found a
matching mailitem.  Only the last dimension can be changed.  So, if my array
of found items looks like this:

    EntryID    StoreID    ReceivedTime
    EntryID    StoreID    ReceivedTime
    EntryID    StoreID    ReceivedTime
    [and so on]

the first dimension (rows) have to be incremented for each successful
search.  To use ReDim, though, I would have to have an array like this:

    EntryID        EntryID        EntryID
    StoreID        StoreID        StoreID
    ReceivedTime   ReceivedTime   ReceivedTime

which of course throws the listbox into chaos.

Is there an "easy" way out of this dilemma?

Thanks again for reading,

Terry



I think arrays default to zero-based -- do you have a 0,0 element that's
blank?


Quote:
> I came up with the following code to a listbox using the List() function,
> but the first element of the list is blank.  Any idea why this should be
and
> how to get all rows from the array displayed?  In single-step mode, the
> array is populated correctly.

> Private Sub UserForm_Initialize()

>     With lstFoundItems
>         .ColumnCount = 3
>         .List() = avarFoundItems
>         .ColumnWidths = "0;0;-1"
>     End With

> End Sub

> Thanks again,
> Terry



> I use similar methods all the time. You just need to set the list box to
> display only one column -- set that column's width (and the one for the
> date) to whatever you want, then set the columns for the entryID and
storeID
> to 0 width.



> > After the search is complete, I'd like to display a ListBox with, say,
the
> > folder name and the MailItem.CreationDate which will allow the user to
> > select and open one of the found MailItems.  Trouble is, I don't want to
> > display the EntryID and StoreID in the dialog, but I _would_ like to use
> > them to find and open a selected MailItem once the user double-clicks an
> > item on the list.  It appears that if I populate the ListBox with the
> List()
> > method, all the elements in my array will be displayed in the ListBox.
> Can
> > the elements be restricted to just a few without losing the convenience
of
> > the List() method?  If not, what other means are available for
populating
> > the ListBox?



Wed, 06 Jul 2005 04:04:15 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Getting oroginal mailitem to a reply mailitem.

2. How to find out, that MailItem was sent

3. Find SubFolder and Folder given the mailitem

4. Find folder where a mailitem is stored?

5. Error finding mailitem in the outbox

6. MailItems.Find() works sometimes

7. Mapping new CDO mailitem to MAPI mailitem

8. how to find sender from mailitem

9. FIND a literal string in an OL mailitem subject

10. Newbie: How to set txt box to be visible, with option from combo list

11. MS/Word VB command option list?

12. add option to select list

 

 
Powered by phpBB® Forum Software