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

ID: Q201051


The information in this article applies to:
  • Microsoft Outlook 2000


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 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.asp
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

  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. Set the Subject to "This is Form1."


  4. On the Tools menu, click Forms, and then click Design This Form.


  5. 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.


  6. 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 


  7. 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.


  8. Close and do not save changes to the item.


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 


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 : kbdta OffVBS
Version : WINDOWS:2000
Platform : WINDOWS
Issue type : kbhowto


Last Reviewed: November 13, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.