s there a way to have a VBA script for Outlook 2007 to display the latest email in Inbox searchin a User-Define filed

We need have the user know the last email that has been received that has a specific value a User-Defined field called 'TYPE'.  Is there a way to go about in a VBA script?

We have been assisted by an EE on searching the latest emails searching within the InBox, the contents of "Sender" field (see http://www.experts-exchange.com/Software/Office_Productivity/Groupware/Outlook/Q_27498826.html?cid=1575#a37304786)
rayluvsAsked:
Who is Participating?
 
Chris BottomleyConnect With a Mentor Software Quality Lead EngineerCommented:
Sure thing ... as long as the mail item property is displayed for the folder itself:

Adding via VBA would be:

application.ActiveExplorer.Selection(1).UserProperties.Add "TYPE", olText, true

Which adds the folder display capability otherwise from the application add the property to the folder properties bar at the top.

Chris
Sub userPropFilter()
Dim olFolder As Object
Dim filteredItems As Object
Dim folderItems As Object
Dim sortedItems As Object
Dim strFilter As String

    Set olFolder = Application.Session.GetDefaultFolder(olFolderInbox)
    Set folderItems = olFolder.Items
    strFilter = "[TYPE] = 'fred'"
    Set filteredItems = olFolder.Items.Restrict(strFilter)
    
    filteredItems.Sort "receivedtime", True
    If filteredItems.Count = 0 Then
        MsgBox "No such mail found"
    Else
        filteredItems(1).GetInspector.Activate
    End If

End Sub

Open in new window

0
 
rayluvsAuthor Commented:
Where do I add "application.ActiveExplorer.Selection(1).UserProperties.Add "TYPE", olText, true"
0
 
Chris BottomleySoftware Quality Lead EngineerCommented:
You don't, I merely mentioned it in case you were dding properties in VBA.

As long as the mailitems have the property and the folder display of the property is selected then all you need is the code I posted in the snippet.

Chris
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
rayluvsAuthor Commented:
Understood.

But it didn't work.  I have the InBox's User-Defined column set so I can alter the TYPE column of any email by placing any value.  In this case I place "fred" in random emails to  test the script; but fails to detect the value.
0
 
rayluvsAuthor Commented:
No wait, t worked.  I changed the TYPE value to how i have it and is Type not TYPE.  It seems to be case sensitive.
0
 
rayluvsAuthor Commented:
2 last question prior closing question:

  - In this recent script, can we use like? (I tried it and it didn't work)

  - Noticed in the previous question which you assisted, you used "like":

       strFilter = "@SQL=" & Chr(34) & "urn:schemas:httpmail:fromemail" & Chr(34) & " like " & "'%" & 
       "MCAGROUP" & "%'
"

    Can we use "urn:schemas:httpmail:fromemail" for User-Defined fields instead?
0
 
Chris BottomleySoftware Quality Lead EngineerCommented:
Use wild cards for userproperties, Not to my knowledge because they are MS specific.  I have not had time to experiement but will try later out of interest.

Chris
0
 
rayluvsAuthor Commented:
I think we got; it's a combination of these 2 links:

http://msdn.microsoft.com/en-us/library/ms526936(v=EXCHG.10).aspx
http://www.pcreview.co.uk/forums/do-custom-form-fields-save-t2234279.html 
(the entry labeled '16th Nov 2005')

So to search for a specific value within a User-Defined filed use:

    strFilter = "@SQL=" & Chr(34) & "http://schemas.microsoft.com/mapi/string/{00020329-0000-0000-C000-000000000046}/USER_DEFINED_FILED_NAME" & Chr(34) & " like " & "'%" & "PLACE_SEARCHDATA_HERE" & "%'"

Where USER_DEFINED_FILED_NAME is the actual UserDefined Column name and the
PLACE_SEARCHDATA_HERE is the search filter desired.

Please advice.
0
 
rayluvsAuthor Commented:
One last question so we can close, please advice on how to display the User-Defined Field Contents using MsgBox.

We're trying to display the contents of the USer-Defined Field.

We want the script to find the recent email with "fred" as it does, but instead of displaying the email, we would like to display the actual contents.  For example, the content of User-Defined Field Type would display 'fred proyect'

0
 
rayluvsAuthor Commented:
Hi chris_bottomley.  I tgink this question has been answered.  I placed another question that we need to work with.  Please follow the link for assistance:

http://www.experts-exchange.com/Software/Office_Productivity/Groupware/Outlook/Q_27499631.html

Thanx

We will proceed to close this question (nevertheless, if you can answer question ID: 37305625, it will be greatly appreciated)
0
 
rayluvsAuthor Commented:
Thanx
0
 
Chris BottomleySoftware Quality Lead EngineerCommented:
Just got in to try and see if I can find a way to access userproperties using DASL and I see you have beaten e to it ... I made a quick test and indeed it works so well done!

Chris
0
 
rayluvsAuthor Commented:
Ok please follow up on the link of the question we recently placed.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.