• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 177
  • Last Modified:

outlook search

I have to perform search on the outlook.pst files programmatically.
I have to search the subject and body of the mails as it is provided in microsoft outlook itself.
for eg if i have a search criteria like
"welcome town"
if the subject of my first mail in outlook is
"welcome" and the second one has "welcome hello town"
then only the second one should come
i have used restrict method of outlook 9.0 object library but i get the result only if i give the whole subject as search string ie
"welcome hello town"
Waiting for the reply.Thanks!!!!!
Urgent...
0
shivanit
Asked:
shivanit
1 Solution
 
Ryan ChongCommented:
Hi shivanit,

Here is an example:

Private Sub Command3_Click()
    Dim iOutlook As Outlook.Application
    Dim myitem As Outlook.MailItem
    Dim myFolder As Outlook.MAPIFolder
    Dim myAttach As Outlook.Attachment
    Dim SearchString As String
   
    SearchString = "Welcome"
    Set iOutlook = New Outlook.Application
   
    Set myFolder = iOutlook.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox)

    List1.Clear
    For i = 1 To myFolder.Items.Count
        Set myitem = myFolder.Items(i)
        If InStr(1, myitem.Subject, SearchString) > 0 Then 'If InStr(1, myitem.Subject, SearchString) = 1 Then 'Perform Like% method
            List1.AddItem myitem.SenderName & " " & myitem.Subject
            DoEvents
        End If
    Next i
    Set myitem = Nothing
    Set myFolder = Nothing
    Set iOutlook = Nothing
End Sub

Hope this help
0
 
DanRollinsCommented:
Hi shivanit,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Accept ryancys's comment(s) as an answer.

shivanit, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept this comment as an answer.
==========
DanRollins -- EE database cleanup volunteer
0
 
kodiakbearCommented:
Moving to the PAQ

kb
Experts Exchange Moderator
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now