Alert uset if a duplicate exists?

J

Jenai

I have created a Customer ID field in my public contacts form and they all
must be different, so is there a way that I can create a rule or action of
some sort to the properites of that field that will not accept or flag an
alert that a duplicate exists?
 
S

Sue Mosher [MVP-Outlook]

You could put code in the Item_Write event handler to check for a duplicate number using MAPIFolder.Items.FInd.
 
J

Jenai

Thank you very much for your help but I'm not totally clear on how I would do
that? Is this something I can do in the 'design form' mode? or is it way more
indepth then that? is there a link that I could go to to help explain this
further?
 
S

Sue Mosher [MVP-Outlook]

Yes, you enter form code while in the form design mode. Click the View Code button. See http://www.outlookcode.com/d/forms.htm for other form basics and samples.

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

Jenai

So I'm able to find the Item_Write event handler in the View Code section but
where I am having my problem now is on writing the actual code, I'm not a
programmer and I guess this must be something way more indepth then I
realized! I went onto the webpage you suggested but I wasn't able to find
specifics on how to begin writing a basic code? I'll keep searching though,
thanks.
 
S

Sue Mosher [MVP-Outlook]

If you have never written any code at all or any Outlook code in particular, you might want to start with the tutorials at http://www.outlookcode.com/d/vb.htm.

While you're building a little comfort level with procedures, statements, and variables, start thinking about how to break down your project logically into steps, without worrying about the actual code. For example, your scenario might look something like this:

0) When the user tries to save an item??? (or when the user sets the Customer ID???)

1) Get Customer ID from current item.

2) Check folder to see if any other item has that ID.

3) then do what ????

Once you have your scenario fleshed out, we can start filling in the code snippets.

(I should say by word of explanation that I believe in teaching people how to fish, not just serving up flounder. If you're designing custom forms, you need to be able to do at least a little VBScript programming.)

An alternative approach is to look at where the customer id values come from in the first place and use a process that guarantees a unique ID without the need to check for duplicates. That's going to be tied to your business process as much as anything else.
--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
J

Jenai

So as you suggested, I was able to clearly outlined what I'm looking for:

1) When the user tabs off the Customer ID. (which I believe would utilize
the Item_Write event handler, you mentioned earlier)
2) Get Customer ID from current item.
3) Check folder to see if any other item has that ID.
4) Alert user that a duplicate exists.

I hope that makes sense? and now I'm going continue to read throught the
tutorials you suggested. Your right, it helps just that I know now what I
actually want to happen in clear steps! Thanks.
 
S

Sue Mosher [MVP-Outlook]

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

 

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