Microsoft KB Archive/201051

= OL2000: How to Automatically Close a Form When Calling an Action =

Article ID: 201051

Article Last Modified on 11/23/2006

-

APPLIES TO


 * Microsoft Outlook 2000 Standard Edition

-



This article was previously published under Q201051



SUMMARY
This article describes how you can automatically close a form after a second form is launched from the first.



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

When you design a form solution in Microsoft Outlook, you can use actions on a form to launch a second form. You may want to have the first form close automatically when the second form is launched.

To do this, follow these steps:

Set Up the Folder

 * 1) Create a new Public folder and set the type so that it contains Mail messages.
 * 2) Right-click the folder, click Properties, click the Administration tab, and then click Personal Address Book to add the folder's address to the Personal Address Book. If the button is not available make sure you have a Personal Address Book service available in your Exchange profile.

Create the Second Form First

 * 1) Open a new mail message.
 * 2) Click To on the form, select Personal Address Book from the list of available address books, select the name of the public folder, and then click "To:->". Click OK.
 * 3) Change the Subject of the message to "This is Form2".
 * 4) On the Tools menu, click Forms, and then click Design This Form.
 * 5) On the Tools menu, click Forms, and then click Publish Form As. For this example, select the Personal Forms Library, although you can also publish the form to another location. Set the Display Name to Form2 and then click Publish.
 * 6) Close and do not save changes to this item.

Create the First Form
 Open a new mail message. Click To on the form, select Personal Address Book from the list of available address books, select the name of the public folder, and then click "To:->". Click OK. Set the Subject to "This is Form1." On the Tools menu, click Forms, and then click Design This Form. On the Actions page, click New. Set the name of the action to "Get Form2." In the Form name list, select Forms... and navigate to the Form2 form that was previously published in the Personal Forms Library. Change the setting to address the form like a "Reply to Folder." Click to select the option to Send the form immediately." Click OK.  On the Form menu, click View Code. Type the following Visual Basic Scripting Edition (VBScript) code into the Script Editor and then close the editor: Function Item_CustomAction(ByVal Action, ByVal NewItem)   Item.Close 1 'olDiscard End Function                         On the Tools menu, click Forms, and then click Publish Form As. Change the Look in setting to Outlook Folders and then click Browse and navigate to the public folder previously created. Type Form1 as the Display Name of the form and then click Publish.</li> Close and do not save changes to the item.</li></ol>

Testing the Forms

 * 1) With the folder selected, on the Actions menu, click New Form1.
 * 2) Click Send.
 * 3) Open the new item in the folder.
 * 4) Click the Get Form2 action.

You will now have no forms open and the folder will receive a new item with a Subject of "This is Form2".

Note: If you do not wish to use actions, you can also publish a second form (Form2) to a forms library and then create a command button on the first form (Form1) and add VBScript code similar to the following:

Sub CommandButton1_Click

' Create a reference to the Inbox Set MyInbox = Application.GetNamespace("MAPI").GetDefaultFolder(6)

' Create a new instance of Form2 Set NewItem = MyInbox.Items.Add("IPM.Note.Form2")

' Address the form and populate its fields NewItem.To = "emailname" NewItem.Subject = "This is form2"

' Send the second form NewItem.Send

' Close the current (first) form Item.Close 1

End Sub

<div class="references_section">