The information in this article applies to:
SUMMARY
The Microsoft Outlook object model is commonly used to access various
types of items in folders. This article provides an overview of the various
methods, properties, and objects that can be used to refer to Outlook items
and folders.
Referencing Existing Folders
Creating and Referencing New Folders
Creating and Referencing New Items
Referencing Existing Items
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 fee-based consulting 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.aspNOTE: Visual Basic Scripting Edition (VBScript) code must use the numeric value of the constants that are defined in the Outlook object library. You can find a listing of these values in the Microsoft Outlook Visual Basic Reference Help file (Vbaoutl9.chm) in the "Microsoft Outlook Constants" topic. Referencing Existing FoldersGetDefaultFolder Method:Default folders are those that are at the same level as the Inbox that receives incoming mail. If you have more than one Inbox in your profile, pressing CTRL+SHIFT+I selects the default Inbox. The default folders are those that most users work with regularly, such as the Calendar, Contacts, and Tasks folders. You can easily refer to these folders using the GetDefaultFolder method. GetDefaultFolder takes one argument, which is the type of folder you want to refer to. The following examples assign the object variable <MyFolder> to the default Contacts folder:
Folders ObjectYou can use the Folders object to refer to any folder that is visible in the Outlook folder list. This object is typically used to refer to an Exchange public folder or any other folder that is not a default Outlook folder.The following examples illustrate how to refer to a public folder called "<My Public Folder>." Note that you typically start at the top-most folder and work your way down to the folder you need to reference. Also note that the folder names are case-sensitive and must exactly match the names as they appear in the Outlook folder list.
The following examples illustrate how you can refer to a folder called
"Business Tasks," which is a subfolder of the default Tasks folder.
Parent PropertyIf you already have a reference to an Outlook item or folder, then you can use its Parent property to create a reference to the folder the item or folder is located in.The following examples return the name of a folder for a particular item:
GetSharedDefaultFolderYou can use this method if someone has given you delegate permissions to one of their default folders.For additional information about accessing other people's folders, please see the following article in the Microsoft Knowledge Base: Q195781 OL2000: (CW) How to Open Someone Else's Calendar or Other Folder The GetSharedDefaultFolder method is used in the same fashion as GetDefaultFolder, except you specify one additional argument -- the name of the other person's folder you want to reference. This example first resolves the other person's name to verify that it is a valid name that can be used with the GetSharedDefaultFolder method.
GetFolderFromIDThis method would typically be used only in more complex solutions where a solution keeps track of both the StoreID and EntryID of a folder so that it can be quickly referenced at a later time.For additional information about using the GetFolderFromID method, please see the following article in the Microsoft Knowledge Base: Q201074 OL2000: Programming with EntryIDs and StoreIDs Creating and Referencing New FoldersFolders.Add MethodUsing the Add method on the Folders collection allows you to create a new folder. The first argument specifies the name of the folder and the second argument specifies the type of folder. The following example adds a <Business Tasks> subfolder in your default Tasks folder. Because the folder type is not specified, it will inherit the type of the parent folder.
Creating and Referencing New ItemsCreateItem MethodThe CreateItem method creates a new default Outlook item. If you need to create an item based on a custom form you have created, use the Items.Add method below. The CreateItem method is conveniently located off of the top- level application object in the Outlook object model. The method takes only one argument, a constant indicating the type of item to create.
Items.Add MethodUsing the Add method on the Items collection allows you to create a new item based on any message class, whether it is a default Outlook message class such as IPM.Contact, or a message class for a custom form, such as IPM.Contact.MyForm. In order to use the Items.Add method, you must first reference the folder where you want to create a new item.For additional information about message classes, please see the following articles in the Microsoft Knowledge Base: Q207896 OL2000: Working with Form Definitions and One-Off Forms Q201087 OL2000: How to Update Existing Items to Use a New Form The following examples use the Items.Add method to create a new item based on a custom contact form called <MyForm>:
The following examples use the Items.Add method to create a new default contact item:
NOTE: If you use the Items.Add method, it does not matter what the default form for the folder is. You can specify any valid message class as long as it has been published in the folder or has been published in the personal or organizational forms library. CreateItemFromTemplate MethodUse the CreateItemFromTemplate method to create a new item based on an Outlook template file (.oft) or .msg file format. Because most forms are published in a folder or forms library, this method is not commonly used. Probably the most common reason to use this method would be if you were creating a Microsoft Visual Basic Setup program to install forms for an Outlook solution. This would typically be done for users who do not have network access or typically work offline in Outlook. The Visual Basic program would do the following:
Referencing Existing ItemsUsing Items(I) or For Each...NextTypically these approaches are used to loop through all of the items in a folder. The Items collection contains all of the items in a particular folder and you can specify which item to reference by using an index with the Items collection. This is typically used with the For I = 1 to n programming construct.You can use the For Each...Next programming construct to loop through the items in the collection without specifying an index. Both approaches achieve the same result. The following examples use the Items(I) approach to loop through all of the contacts in the Contacts folder and display their FullName field in a dialog box.
The following examples use the For Each...Next construct to achieve the same result as the preceding examples:
Using Items("This is the subject")You can also use the Items collection and specify a text string that matches the Subject field of an item. This approach is not commonly used.The following examples display an item in the Inbox whose subject contains "Please help on Friday!"
Find MethodUse the Find method to search for an item in a folder based on the value of one of its fields. If the Find is successful, you can then use the FindNext method to check for additional items that meet the same search criteria.The following examples search to see if you have any high priority appointments.
Restrict MethodThe Restrict method is similar to the Find method, but instead of returning a single item, it returns a collection of items that meet the search criteria. For example, you might use this method to find all contacts who work at the same company.The following examples display all of the contacts who work at ACME Software:
For additional information about message classes, please see the following articles in the Microsoft Knowledge Base:Q201081 OL2000: Using Find and Restrict to Retrieve Items GetItemFromID MethodThis method would typically be used only in more complex solutions where a solution keeps track of both the StoreID and EntryID of an item so that it can be quickly retrieved at a later time.For additional information about using the GetFolderFromID method, please see the following article in the Microsoft Knowledge Base: Q201074 OL2000: Programming with EntryIDs and StoreIDs 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: Q146636 OL2000: Questions About Custom Forms and Outlook Solutions Additional query words: OutSol OutSol2000 OL2K
Keywords : kbcode kbdta |
Last Reviewed: October 26, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |