The information in this article applies to:
SUMMARYThis article provides an overview of possible solutions for sequentially numbering items in a Microsoft Outlook folder. Outlook does not provide a direct way of automatically incrementing a field value. 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 the Microsoft Consult Line at (800) 936-5200. For more information about the support options available from Microsoft, please see the following page on the World Wide Web: http://www.microsoft.com/support/supportnet/overview/overview.aspMany database-oriented programs, such as Microsoft Access 97, provide a way to create uniquely numbered items (or records). In database terminology, this is typically referred to as a primary key. There are several situations where you might want Outlook to sequentially number items. A form that a helpdesk uses to track task requests is one such example. Each task in a folder would have a unique task number for tracking purposes. Outlook does not provide a way of manually indexing fields in folders like most database management systems (DBMSs). Outlook stores items in MAPI folders, and because these folders are designed to be flexible in terms of what can be placed in them, they are "less structured" than a typical DBMS. The folders are "self-indexing" based on various criteria, such as how often a folder is accessed, and therefore do not have a primary key that you can manually set. Implementation StrategiesIn all of the following scenarios, you have to create Visual Basic Scripting Edition (VBScript) code with event procedures for the form, typically Item_Open. VBScript code in the Item_Open event keeps track of the auto-incrementing number, or ID, for the items. You then store the number assigned to the last form item in some designated location. Choosing the storage location is the main difference between the following strategies.Examples below auto-increment the ID number in the Mileage field, because the Mileage field is available in all types of Outlook forms. In general, the code placed in the Item_Open event needs to determine if the form is a new form or whether the form is an existing form. If it is a new form, VBScript code needs to retrieve, increment, and store the ID in the Mileage field. Then the code needs to update the number wherever the "last used" ID is stored so that it is ready for the next new form. If the form is an existing form, the VBScript code typically does nothing related to the ID number. Increment Number and Republishing the FormThis approach uses a published form to keep track of the ID number. Because the Item_Open event executes when a new item is created or when an existing item is opened, the VBScript code has to test to see whether the index needs to be incremented.The following is sample code to provide a starting point for implementing this type of solution. Because VBScript cannot use Outlook constants, the constants are explicitly defined at the beginning of the code. To implement this solution, follow these steps:
Use Microsoft Access 97 to Generate the Unique IDYou can use this method as part of a much larger data-synchronizing solution between Outlook and Microsoft Access. For example, you store a master copy of contact data in Microsoft Access. In this case, you match the Mileage field to a primary key field in Microsoft Access.A custom Outlook contact form can have an Item_Open event in VBScript that checks the Mileage field and then uses Data Access Objects (DAO) to retrieve the information for the contact. If the Mileage field is empty, this means the user created a new contact item and DAO code is used to create a new contact record in the Microsoft Access database. This automatically generates a unique ID for the record, and code can retrieve and store this ID in the Outlook Mileage field. Use an Item in a FolderInstead of using a published form, an Outlook item can store the last-used ID number. If you place the item in the same folder as the other numbered items, one issue to consider is that someone might accidentally delete the item storing the last-used number. To safeguard this, you can store the item in a different folder.Text FileStore the last-used number in a separate text file on the hard disk using the FileSystemObject that is available with VBScript versions later than 1.0.REFERENCESFor more information about creating solutions with Microsoft Outlook 98, please see the following articles in the Microsoft Knowledge Base: Q180826 OL98: Resources for Custom Forms and Programming Additional query words: OutSol OutSol98 count
Keywords : OffVBS |
Last Reviewed: November 13, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |