How to search for blank userproperties field

Roland Askew

New Member
Outlook version
Outlook 2010 32 bit
Email Account
IMAP
I am trying to search through my task that have a userproperties field "Project". I want to loop through all the tasks that have an entry and ignore the task where the field is blank. I have not been able to work out how to search is not blank.

So far I have the following code which finds the tasks which have "test project" as a value in the project field and displays them. Any help to search for all tasks that the Project field is not empty would be really helpful.
Thanks
Roland

Public Sub Project()
Dim ns As NameSpace
Dim objFolder As MAPIFolder
Dim currrentItem As Object
Dim objTasks As TaskItem
Dim colItems As items

Set ns = Application.GetNamespace("MAPI")
Set objFolder = ns.GetDefaultFolder(olFolderTasks)
Set objItem = objFolder.items

Dim strWhere As String

strWhere = "[Project] = 'Test Project'"

Set colItems = objFolder.items.Restrict(strWhere)

For Each Item In colItems
Item.Display
Next

End Sub
 

Michael Bauer

Senior Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
That doesn't work with the Restrict function. Instead you need to loop through the Items collection, and check each item's field.

For , say, a thousand tasks the above is an easy to implement solution. If you have to search regularily within, say, ten thousand tasks, I'd recommend using the Redemption, which supports a filter for that and is a lot faster.
 

Roland Askew

New Member
Outlook version
Outlook 2010 32 bit
Email Account
IMAP
Thank Michael for taking the time to answer my question. In case anyone is interested I did manage to solve my problem by creating the strWhere using the @sql statement.
The new statement now is as follows and finds all the task that have an entry in the userproperties "project" field.

strWhere = "@SQL=NOT(""http://schemas.microsoft.com/mapi/string/{00020329-0000-0000-C000-000000000046}/Project"" IS NULL)"

Hope this may help others in the future.
Roland
 

Michael Bauer

Senior Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
Wow, thanks a lot! According to the VBA help file, SQL statements don't work with the Find, and Restrict functions. And that's the answer that was given since many years.
 

Roland Askew

New Member
Outlook version
Outlook 2010 32 bit
Email Account
IMAP
It got this information from a posting by Ken Slovak and apparently the "@SQL" has to be used with DASL syntax property tags.
Roland
 
Top