Microsoft KB Archive/186437

= OL98: How to Programmatically Publish a Form =

Article ID: 186437

Article Last Modified on 11/23/2006

-

APPLIES TO


 * Microsoft Outlook 98 Standard Edition

-



This article was previously published under Q186437



SUMMARY
This article provides code samples that show how the Outlook object model can be used to publish a form. The samples cover using Microsoft Visual Basic and Microsoft Visual Basic Scripting Edition (VBScript) to perform this task.



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 a Microsoft Certified Partner or the Microsoft fee-based consulting line at (800) 936-5200. For more information about Microsoft Certified Partners, please visit the following Microsoft Web site:

https://partner.microsoft.com/global/30000104

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

Microsoft Outlook Form
The following steps create a custom Outlook form that programmatically publishes a form in the Inbox:  Open a new mail message. On the Tools menu, click Forms and then click Design This Form. Click the (P.2) page of the form. On the Form menu, click Control Toolbox. Use the Control Toolbox to add a Command Button to page P.2.  On the Form menu, click View code. Type or copy the following code into the VBScript code window of the form and then close the editor: Option Explicit Dim olNS Dim MyFolder Dim MyItem Dim MyForm

Sub CommandButton1_Click Set olNS = Item.Application.GetNamespace("MAPI") Set MyFolder = olNS.GetDefaultFolder(6) '6=olFolderInbox Set MyItem = Application.CreateItem(0) '0=MailItem Set MyForm = MyItem.FormDescription MyForm.Name = "MyInboxForm" MyForm.PublishForm 3, MyFolder         '3=olFolderRegistry Item.Close 1                           '1=olDiscard End Sub  On the Tools menu, click Forms and then click Publish Form As. Select the Inbox as the destination, enter MyForm as the Display Name, and then click Publish. Choose either Yes or No when you are prompted about sending the form definition with the item. Close and don't save changes to the form. On the Actions menu, click New MyForm. Click the P.2 page of the form and click the button.</li></ol>

This will open a new instance of MyForm and publish it to the Inbox as MyInboxForm. You can verify this by clicking the Actions menu and seeing New MyInboxForm listed at the bottom of the menu.

Visual Basic Project
Use the following steps to create a Microsoft Visual Basic 5.0 project to demonstrate how to programmatically publish a form into the Inbox: <ol> Create a new standard Visual Basic project.</li> Create a reference to the Outlook 98 Type Library.</li> Add a command button to the Form.</li>  Type or paste the following code into General Declarations section of the form code window. Option Explicit Dim olApp As Outlook.Application Dim olNS As Outlook.NameSpace Dim olFolder As Outlook.MAPIFolder Dim olItem As Outlook.MailItem Dim myForm As Outlook.FormDescription

Private Sub Command1_Click Set olApp = CreateObject("Outlook.Application") Set olNS = olApp.GetNamespace("MAPI") olNS.Logon, , True, True Set olFolder = olNS.GetDefaultFolder(olFolderInbox) Set olItem = olApp.CreateItem(olMailItem) Set myForm = olItem.FormDescription myForm.Name = "MyInboxForm" myForm.PublishForm olFolderRegistry, olFolder Unload Me     End Sub </li> When you run this Visual Basic application, it publishes a new form in the Inbox and gives it a new name.</li></ol>

<div class="references_section">