How to search for blank userproperties field

Status
Not open for further replies.

Roland Askew

Member
Outlook version
Outlook 2021 64 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
 
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.
 
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
 
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.
 
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.
Similar threads
Thread starter Title Forum Replies Date
M Search message, then (1) Jump to folder & (2) Select message that you searched for Outlook VBA and Custom Forms 7
G Search Folders and Jump to Folder Outlook VBA and Custom Forms 2
A 'search people' now asks me to 'press enter' Using Outlook 11
A Relocate Search Bar in Outlook Using Outlook 2
A Search folder and move the email Outlook VBA and Custom Forms 0
farrissf Outlook 2016 Optimizing Email Searches in Outlook 2016: Seeking Insights on Quick Search vs Advanced Search Features Using Outlook 0
C Advanced search terms for "Outlook Data File" Using Outlook 1
T How to find or display the sub-folder name for an Archive Search Using Outlook 10
P Search folder: all emails sent to or from a domain Using Outlook 1
T Outlook365 search item listed as "potential matches" can't be opened Using Outlook 0
Victor_50 Outlook 2019 Jump to folder from search folder Outlook VBA and Custom Forms 0
E Outlook 365 Save Selected Email Message as .msg File - oMail.Delete not working when SEARCH Outlook VBA and Custom Forms 0
Witzker Outlook 2019 Macro GoTo user defined search folder Outlook VBA and Custom Forms 6
J Outlook search bar in Office 2021 Professional Using Outlook 1
T Outlook 365 Search Box reverting to old location Using Outlook 2
P Outlook 2013 search no longer works Using Outlook 2
C How to search for items in Outbox with multiple accounts? Using Outlook 20
J search doesn't find anything Using Outlook 1
kkqq1122 How would I add Search for attachment name Outlook VBA and Custom Forms 3
A Any way to force sort by/group by on search results with VBA? Outlook VBA and Custom Forms 1
B Search and Find Email by Folder Name Outlook VBA and Custom Forms 2
C Search not accurate, but not indexing Using Outlook 9
J How do you disable address search box when typing @ in body of email? Using Outlook 0
H Outlook 2019 intermittent search results Using Outlook 0
D Create advanced search (email) via VBA with LONG QUERY (>1024 char) Outlook VBA and Custom Forms 2
D Advanced e-Mail search on from/to contact group only searches for first 20 contacts in group Using Outlook 0
mll persistently customise columns in outlook advanced search Using Outlook 3
S vba outlook search string with special characters Outlook VBA and Custom Forms 1
S VBA search string with special characters Outlook VBA and Custom Forms 1
H Search Email Header for Content Type Outlook VBA and Custom Forms 1
P Posts in Folder No Longer Group by Conversation Column After Search Using Outlook 0
O Advanced search - can I use booleans Using Outlook 3
Y Filter unread emails in a search folder vba help Outlook VBA and Custom Forms 0
M Reverting The Outlook Search Box Location (or other undesired additions) Using Outlook 1
M Something went wrong and your search couldn't be completed Using Outlook 1
M Disable Contact Card Results when using "Search People" in Outlook Ribbon Using Outlook 7
J outlook 2007 doesn't let me choose which .pst to search Using Outlook 2
P outlook 2008 search box criteria couldn't be saved Using Outlook 2
C Outlook with Office365 - search across account, by date rate, in multiple folders - how? Using Outlook 2
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

Similar threads

Back
Top