Searching for UserProperty

W

wizeguy

I'm storing a unique number with a journal item. I want to be able to
search by that number and modify that entry later on. So far I can get
it stored fine by doing this.

Store info
=============
<snip>
Dim MyEntryID As Outlook.UserProperty
Set MyEntryID = MyOlItem.UserProperties.Add("EntryID", olText)
MyEntryID.Value = MyTime
<snip>

I can see the values stored in outlook but I'm unable to find the entry
thru code?

Look for entry
===============
<snip>
Dim objNameSpace As Outlook.NameSpace
Dim objJournals As Outlook.MAPIFolder
Dim objJournal As Outlook.UserPropert
Set objNameSpace = MyOlApp.GetNamespace("MAPI")
Set objJournals = objNameSpace.GetDefaultFolder(olFolderJournal)
This line needs help > Set objJournal = objJournals.UserProperties.Find("EntryID").Value = MyTime
<snip>

Thanks. :)
 
S

Sue Mosher [MVP-Outlook]

Three problems:

1) Outlook items already have a property named EntryID. You can't create a custom property with the same name. Pick another name. I used NewEntryIDProperty in the example below.

2) You're using Find on the wrong object. When you want to locate an item in a folder, you need to use the Find method on the folder's Items collection.

3) If the value you're searching for is a string literal, it must be enclosed in quotation marks:

strFind = "[NewEntryIDProperty] = " & Chr(34) & somevalue & Chr(34)
Set itm = objJournals.Items.Find(strFind)
If Not itm Is Nothing Then
' do stuff with itm
End If

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top