Microsoft KB Archive/165514

= OL97: How to Create a New Item Based on a Custom Form =

Article ID: 165514

Article Last Modified on 2/12/2007

-

APPLIES TO


 * Microsoft Outlook 97 Standard Edition

-



This article was previously published under Q165514



SUMMARY
This article describes how you can use Outlook 97 Visual Basic Scripting Edition to create a new item based on a custom form.



MORE INFORMATION
Microsoft 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://support.microsoft.com/default.aspx?scid=fh;EN-US;CNTACTMS

When a form is published in Outlook 97, a message class name is used to identify the form. In VBScript, you can use this class name with the Add method of Outlook's Items collection to create a new item based on the published custom form. To obtain the message class of a custom form, open the custom form and click "Publish Form As" on the File menu. You will see the message class name in the Publish Form As dialog box, for example:

IPM.Contact.CustomContact

The following steps will enable you to use the message class name and VBScript to create another item or copy of the current form, by adding a command button and the attached VBScript to your custom form.

To create the VBScript and command button follow these steps:

 Open a custom form. On the Tools menu, click Design Outlook Form. On the Form menu in Design View, click Control Toolbox. Drag the Command Button to your form from the Toolbox. On the Form menu, click View Code to open the Script Editor.  In the Script Editor, type the following code and substitute the message class name for your custom form: Sub CommandButton1_Click Set MyFolder = Item.Application.ActiveExplorer.CurrentFolder Set MyItem = MyFolder.Items.Add("") MyItem.Display End Sub </li> On the File menu in the Script Editor, click Close to return to your form.</li> On the Tools menu, click Design Outlook Form to switch out of the Design View.

NOTE: If the Script Editor detects an error in your code, it will display a message at this point.</li> On the File menu, click Publish Form As and then click Publish.</li> On the File menu, click Close. Do not save changes when prompted.</li></ol>

<div class="references_section">