Article ID: 201099 - Last Review: November 23, 2006 - Revision: 3.2 OL2000: Working with Keywords Fields from VBScriptThis article was previously published under Q201099 On This PageSUMMARY
This article describes how to programmatically access the contents of both
standard and custom keywords fields in Microsoft Outlook using Microsoft
Visual Basic Scripting Edition (VBScript). Concepts in this article also apply to solutions based in Visual Basic or Visual Basic for Applications.
MORE INFORMATIONMicrosoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs. If you have limited programming experience, you may want to contact a Microsoft Certified Partner or Microsoft Advisory Services. For more information, visit these Microsoft Web sites: Microsoft Certified Partners - https://partner.microsoft.com/global/30000104 (https://partner.microsoft.com/global/30000104) Microsoft Advisory Services - http://support.microsoft.com/gp/advisoryservice (http://support.microsoft.com/gp/advisoryservice) For more information about the support options that are available and about how to contact Microsoft, visit the following Microsoft Web site:http://support.microsoft.com/default.aspx?scid=fh;EN-US;CNTACTMS (http://support.microsoft.com/default.aspx?scid=fh;en-us;cntactms) Outlook items can contain information that is stored in a keywords format. The format is typically used to represent a grouped list of information such as company names and categories. For example, you might want to use a keywords field to store a list of companies that a salesperson is responsible for. However, keywords fields are most commonly associated with the standard Categories field, which is available on all Outlook forms. This field is used to categorize items even though they are not stored in the same location. Standard Keywords FieldsOutlook provides three standard keywords fields.Field name Forms available in: ---------- ------------------- Categories All Companies Contact, Task, Task Request, Journal Entry Children Contact When accessing these standard keywords fields through the Outlook object model, they are treated like a standard text field. For example, if the Categories selected for a contact are Personal, Phone Calls, and Waiting, the following line of VBScript code will set the MyCategories variable equal to the entire list of categories: User-Defined (Custom) Keywords FieldsIt is not possible to directly modify the contents of a user-defined keyword field using VBScript. Outlook uses a different variation of array data type than that supported by VBScript, and therefore a "Type mismatch" error message will appear if you try to display the text of the field in a message box, assign the field to an array variable, or perform any string-related function on it.For example, if you create a keywords field called MyKeywords, the following two lines of code will both generate a " Type mismatch " error message: Accessing the Text Via a ControlYou can work around this limitation by "filtering" the text through a control. For example, you can place a text box (Textbox1) on a form page (P.2) and bind this text box to a user-defined keywords field (MyKeywords). The following steps create sample code that adds the word "New" to the beginning of the MyKeywords field.NOTE: If you do not want to display the text box used to gain access to the keywords text, you can right-click the text box, click Properties, and clear the Visible property on the Display tab of the Properties window.
Using a Standard Keywords FieldIf one of the standard keywords fields is not being used and it is available, based on the type of form you are using, see the "Standard Keywords Fields" table earlier in this article. You can use that field to gain access to the text in the field. You can temporarily assign the value of your custom keywords field to the standard field, modify the text while it is in the standard field, assign the standard field back to your custom keywords field, and then delete the contents of the standard field you temporarily used. The following sample code provides an overview of this process:REFERENCES
For additional information about available resources and answers
to commonly asked questions about Microsoft Outlook 2000 solutions,
please see the following article in the Microsoft Knowledge Base:
OL2000: Questions About Custom Forms and Outlook Solutions
(http://support.microsoft.com/kb/146636/EN-US/
)
| Article Translations
|
Back to the top
