OL98: How to Automatically Close a Form When Calling an Action
ID: Q193460
|
The information in this article applies to:
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 98, 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
- To store mail messages, create a new Public Folder.
- Right-click the folder, click Properties, click the Administration tab,
and then click the "Personal Address Book" button to add the folder's
address to the Personal Address Book. If the button is not enabled,
make sure you have a Personal Address Book service available in your
Exchange profile.
Create the Second Form First
- 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.
- Change the Subject of the message to "This is Form2".
- On the Tools menu, click Forms, and then click Design This Form.
- 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.
- 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 form like a
"Reply to Folder." Enable 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.
- Close and do not save changes to the item.
Testing the Forms
- With the folder selected, on the Actions menu, click New Form1.
- Click Send.
- Open the new item in the folder.
- 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
NOTE: One approach that will not work is trying to use Visual Basic Script
to close an item from within its own Send event. Outlook will typically
generate the following error:
One or more parameter values are not valid.
REFERENCES
For more information about creating solutions with Microsoft Outlook 98,
please see the following articles in the Microsoft Knowledge Base:
Q180826
OL98: Resources for Custom Forms and Programming
Q182349
OL98: Questions About Custom Forms and Outlook Solutions
Additional query words:
OutSol OutSol98
Keywords : kbdta OffVBS
Version : WINDOWS:
Platform : WINDOWS
Issue type : kbhowto
|