How to search for blank userproperties field

Status
Not open for further replies.

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
 
Status
Not open for further replies.
Thread starter Similar threads Forum Replies Date
J Outlook messages aren't indexing in Search; "Index messages in these data files" is blank Using Outlook 17
C Outlook with Office365 - search across account, by date rate, in multiple folders - how? Using Outlook 1
D Custom Search Folders not refreshing/updating automatically Using Outlook 0
L New Location for the Search Bar Using Outlook 6
T How can you include Junk Email in Search Results like you can include Deleted Items? Using Outlook 3
J Outlook 2016 After a search in all mailboxes, where is each message that was found? Using Outlook 6
King Mustard Sort search groups by amount of items? Using Outlook 1
V Outlook 2016 will not move emails in search results Using Outlook 4
T Search for incoming e-mails for a specified time range Using Outlook 1
S outlook 2007 calendar search Using Outlook 6
M Outlook macro to automate search and forward process Outlook VBA and Custom Forms 6
J Message search and edit, another way? Outlook VBA and Custom Forms 4
S Create A Search Folder That Looks For Message Class? Outlook VBA and Custom Forms 0
R Outlook for Mac - Advanced Search and Tracking Sent Emails Using Outlook 0
R Search/Jump to a folder by typing its name Outlook VBA and Custom Forms 1
M Sent mail not showing in Sent Items folder; but they can be found with Search Using Outlook 3
A Outlook 2019 having issues with 'people search' and not making suggestions in email To: etc Using Outlook 12
W Search Incomplete Outlook 2016 Using Outlook 5
S Outlook 2007 Calendar instant search problem. Windows 7 Using Outlook 4
S Outlook 2007 Calendar instant search problem. Windows 7 Using Outlook 0
A Using or not using apostrophes in search terms has this changed? Using Outlook 0
R outlook address book search broken Using Outlook 2
K Outlook.com is not showing, or finding via search, all my Contacts (People) Using Outlook 0
W Create Search Folder excluding Specific Email Addresses Using Outlook 5
R What's supposed to appear when just clicking into the search field? Using Outlook 7
A Outlook macro to create search folder with mail categories as criteria Outlook VBA and Custom Forms 3
M possible to search Outlook for multiple email addresses at once? Using Outlook 1
B Instant search with special characters Using Outlook 1
A Search folder refresh Outlook VBA and Custom Forms 3
B Advanced Search in MS Outlook by VBA and SQL Outlook VBA and Custom Forms 2
M email search not working Using Outlook 1
F Search folder for tasks in all task folders Using Outlook 1
W Outlook 2016 search problem persists after applying all known solutions Using Outlook 12
B Looking to filter (or just find/search) for only messages that the sender has sent more than 1 messa Using Outlook 2
B Search: Cannot find which Folder Contains a Message Using Outlook 3
M how to speed up search of shared contacts Using Outlook 0
B When I add more search strings to RULES, it is not processing them Using Outlook 3
C Search with Google Macro? Outlook VBA and Custom Forms 4
E Search for folder by key in subject then move new message to related folder Outlook VBA and Custom Forms 1
E Outlook 2016 Inbox search bug Using Outlook 1
C Filter/Search emails sent to internal Exchange address only Using Outlook 2
M VBA macro for Inbox's attachments search Outlook VBA and Custom Forms 0
P Outlook search is not working at all for Calendar & Tasks Using Outlook 7
M Recent Update Did not Fix Search Problems Using Outlook 7
Commodore Search cannot complete the indexing of your Outlook data Using Outlook 6
M new search just... sucks Using Outlook 4
B Search function in Office 365 has stopped working Using Outlook 3
J Marco in search of text in subject line Using Outlook 8
T Delete Emails from search results Outlook VBA and Custom Forms 1
P Can't search Archive'd Tasks Using Outlook 0
Similar threads


















































Top