1) When the user tabs off the Customer ID. (which I believe would utilize
the Item_Write event handler, you mentioned earlier)
Close but not quite. The Write event fires when the item is saved. The event that fires when the user enters a new value for a custom property is CustomPropertyChange. You can read about it and see a sample at
http://www.outlookcode.com/d/propsyntax.htm
2) Get Customer ID from current item.
That same page shows you how to access the value of a custom property using the UserProperties collection.
3) Check folder to see if any other item has that ID.
For this, you'll use the MAPIFolder.Items.Find method, which consists of four steps:
3a) Get the folder. To get a non-default folder, you need to walk the folder hierarchy using the Folders collections or use a function that does that for you. See
http://www.outlookcode.com/d/code/getfolder.htm
3b) Construct a search string. This would look something like:
strFind = "[Customer ID] = " & Chr(34) & <the value from #2> & Chr(34)
3c) Run the search. Once you have the folder it looks like:
Set foundItem = objFolder.Items.Find(strFind)
3d) Check the result. When you're working with objects, an important keyword is Nothing, as used here:
If Not foundItem Is Nothing Then
' you know there is a duplicate
End If
4) Alert user that a duplicate exists.
You can use the MsgBox function to pop up a message box.
Note that nothing in Steps 1-4 changes the value for Customer ID that the user already set. Think about what you want to do about that.
--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers