Solved

Display the resulting search in Outlook 2010 and modify the Outlook displayed result

Posted on 2013-12-03
17
385 Views
Last Modified: 2013-12-25
We are working with a VBA where we want to modify a user-defined column of an item (or email) in a search result displayed.  We have the script that display Outlook windows contents but can't seem to only display the "search result".  

The purpose is access a specific email and change it user-defined column.  But we can't get to display only the result, just the folder contents.
see VBA script
0
Comment
Question by:rayluvs
  • 9
  • 8
17 Comments
 

Author Comment

by:rayluvs
ID: 39692925
forgot scripts:

Script to read in Outlook and get contents:
'GET OUTLOOK CONTENTS
'Set defaults
 Set olFolder = Application.Session.GetDefaultFolder(olFolderInbox)
 Set folderItems = olFolder.Items
    
'Find in Userdefined column PROYECT
 If SearchBy = 1 Then strFilter = "@SQL=" & Chr(34) & "http://schemas.microsoft.com/mapi/string/{00020329-0000-0000-C000-000000000046}/Proyecto" & Chr(34) & " like " & "'%" & ProjectSearch & "%'"
 Set FilteredItems = olFolder.Items.Restrict(strFilter)

Open in new window


Script to save to Outlook email user-defined column:
(giving you this script in case needed for what we need)
'SAVE SELECTED CONTENTS
 If OptionSelected Then
    Dim olkMsg As Outlook.MailItem, olkProp As Object
    For Each olkMsg In Application.ActiveExplorer.Selection
        If TypeName(olkProp) = "Nothing" Then
            Set olkProp = olkMsg.UserProperties.Add("Project", olText, True)
            olkProp.Value = ApoyoSelected
            olkMsg.Save
        End If
        Set olkProp = Nothing
    Next
    Set olkMsg = Nothing
    End If

Open in new window

0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 39694603
Are you expecting the folder to show the restricted set of emails ... because it will not however if at line 9 of your first script you follow up with your second script but at line 4 in that script (as presented) you use the filtereditems set instead of the selection then it should work on only those emails.

Chris
0
 

Author Comment

by:rayluvs
ID: 39700301
Don't quite follow you.

please explain.
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 39700725
The vba code calculates a vba collection IT DOES NOT modify the outlook displayed folder.

You can however merge your two snippets into one with a small change and it would work
0
 

Author Comment

by:rayluvs
ID: 39705092
Understood.  Just don't quite understand on ID: 39694603, the referencing line 9.  Nevertheless, we want to be specific in what we need.  We want to know if possible to modify the first VBA script in ID: 39692925 so it can search within a search result display in Outlook.  The VBA at this as is, searches the entire inbox folder.  

When we say the "search result" is when user types specific data in the field "Search Inbox (Ctrl+E)", Outlook filters the Inbox to what the user text in (see pic below for the field).

sea1
We want the code to search through the result on screen.  

We want to do this because the Inbox is quite big and the search in the first VBA takes a long a long time.  We figure that if we can have the VBA search within the Outlook Search Result, it would be faster.

Hope this helps describe what we are trying to do.
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 39705500
First script remains as was:

'GET OUTLOOK CONTENTS
'Set defaults
 Set olFolder = Application.Session.GetDefaultFolder(olFolderInbox)
 Set folderItems = olFolder.Items
    
'Find in Userdefined column PROYECT
 If SearchBy = 1 Then strFilter = "@SQL=" & Chr(34) & "http://schemas.microsoft.com/mapi/string/{00020329-0000-0000-C000-000000000046}/Proyecto" & Chr(34) & " like " & "'%" & ProjectSearch & "%'"
 Set FilteredItems = olFolder.Items.Restrict(strFilter)

Open in new window


Second script is called after the first script and during the same process of code execution but is modified at line 4 to become:

'SAVE SELECTED CONTENTS
' Save the set of emails picked out by the VBA filter
 If OptionSelected Then
    Dim olkMsg As Outlook.MailItem, olkProp As Object
    For Each olkMsg In FilteredItems
        If TypeName(olkProp) = "Nothing" Then
            Set olkProp = olkMsg.UserProperties.Add("Project", olText, True)
            olkProp.Value = ApoyoSelected
            olkMsg.Save
        End If
        Set olkProp = Nothing
    Next
    Set olkMsg = Nothing
    End If

Open in new window


Chris
0
 

Author Comment

by:rayluvs
ID: 39707304
Ran it and for some reason it takes the same time.  Placed a counter "X = X + 1" and it counted 713 lines when the Outlook filters screen had 45 lines.  Tried it filtering emails that woul return 4 lines, and it still counted 713.  Note the Inbox folder has 3380 emails.

If I filteres diferente types of emails why always displayed a counted values of 713?
0
 

Author Comment

by:rayluvs
ID: 39707308
How can I know wht is in FilteredItems?
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 39707894
Can you supply the combined script you ran please?

Chris
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 39707896
Note filtered items has the sum of items that match your SQL filter, didn't test the filter itself but if you confirm what it is looking for i'll set up a test for the precise conditions to be sure it works.

Chris
0
 

Author Comment

by:rayluvs
ID: 39733805
Hi sorry for the delay.  The script is the one you recommended to change in ID: 39705500 where we change to "FilteredItems".

Yes, that is what we are looking for, we are looping thru "FilteredItems".
0
 
LVL 59

Accepted Solution

by:
Chris Bottomley earned 500 total points
ID: 39733903
You are using a variable projectsearch in your code which if blank will simply return the wild cards.  This is why I asked about the script you are using ... What should the search term look like?

Chris
0
 

Author Comment

by:rayluvs
ID: 39733906
understood, thanx!  Let me try something?
0
 
LVL 59

Assisted Solution

by:Chris Bottomley
Chris Bottomley earned 500 total points
ID: 39733938
Of course but I just ran a test of the sample code:

Sub test_28309084()
'############### SCRIPT 1
'GET OUTLOOK CONTENTS
'Set defaults

Dim olkMsg As Object
Dim olkProp As Object
Dim olkMessage As Object
Dim olkFolder As Object
Dim folderItems As Object
Dim strFilter As String
Const projectSearch As String = "ProjectSearch"
Const searchBy As Integer = 1
    
    Set olkFolder = Application.Session.GetDefaultFolder(olFolderInbox)
    Set folderItems = olkFolder.Items
    
'Find in Userdefined column PROYECT
    If searchBy = 1 Then strFilter = "@SQL=" & Chr(34) & "http://schemas.microsoft.com/mapi/string/{00020329-0000-0000-C000-000000000046}/Proyecto" & Chr(34) & " like " & "'%" & projectSearch & "%'"
    Set FilteredItems = olkFolder.Items.Restrict(strFilter)
 
'############### SCRIPT 2
'SAVE SELECTED CONTENTS
' Save the set of emails picked out by the VBA filter
    If OptionSelected Then
        For Each olkMsg In FilteredItems
            If TypeName(olkProp) = "Nothing" Then
                Set olkProp = olkMsg.UserProperties.Add("Project", olText, True)
                olkProp.Value = ApoyoSelected
                olkMsg.Save
            End If
            Set olkProp = Nothing
        Next
        Set olkMsg = Nothing
    End If
End Sub

Open in new window


With the constant projectSearch undefined, (i.e. without line 12 initially) it returns all items whereas with it set to "projectsearch" (the variable now defined as the string "ProjectSearch") then since I do not have the user defined column it returns 0 items confirming to me what I was saying about the wild card search.

Chris
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 39734018
Note

I will admit to assuming that your returned count of 713 refers to mails with ANY value for the user defined field whereas you are looking for values that match your specific string value.

Chris
0
 

Author Comment

by:rayluvs
ID: 39739478
sorry for the delay but thank you a million!  The problem was the variables which definitely overlooked completely.
0
 

Author Closing Comment

by:rayluvs
ID: 39739679
Thanx!
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Resolve DNS query failed errors for Exchange
If you don't know how to downgrade, my instructions below should be helpful.
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
The viewer will learn how to  create a slide that will launch other presentations in Microsoft PowerPoint. In the finished slide, each item launches a new PowerPoint presentation and when each is finished it automatically comes back to this slide: …

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now