OL97: Supported Outlook Forms Control Events

Last reviewed: March 2, 1998
Article ID: Q171246
The information in this article applies to:
  • Microsoft Outlook 97

SUMMARY

This article describes the three events that are supported by a form's fields and controls in Microsoft Outlook 97.

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 engineers 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/refguide/default.asp

Controls in forms in Outlook can perform three types of events:

   Click
   PropertyChange
   CustomPropertyChange

The Click Event

The Click event occurs when the user clicks a form control. You can create as many Click event procedures as you have controls on a form. The name of each event procedure is the name of the control (such as "CommandButton1"), followed by an underscore character (_) and the word "Click." The following example displays a greeting containing the log on name of the current user whenever the button named "CommandButton1" is clicked:

   Sub CommandButton1_Click()
      MsgBox "Hello " & Application.GetNameSpace("MAPI").CurrentUser
   End Sub

   NOTE: The Message and Note form controls do not support the Click
   event.

   NOTE: If a control is bound to a field, then the Click event will not
   fire. Instead of using the Click event, you should typically use the
   CustomPropertyChange or PropertyChange event when a control is bound
   to a field.

   For more information about the Click event and bound controls,
   please see the following article in the Microsoft Knowledge Base:

      Article-ID: Q166853
      Title     : OL97: Bound Control Does Not Support Click Event

The PropertyChange Event

The PropertyChange event occurs when one of the item's standard properties is changed. The property name is passed to the procedure, making it possible for the procedure to determine which property was changed. The following example disables setting a reminder for an item:

   Sub Item_PropertyChange(ByVal myPropertyName)
   Select Case myPropertyName
      Case "ReminderSet"
         MsgBox "You cannot set a reminder on this item."
         Item.ReminderSet = False
     Case Else
   End Select
   End Sub

The CustomPropertyChange Event

The CustomPropertyChange event occurs when one of the item's custom properties is changed. These properties are the user-defined fields added to the item at design time. The property name is passed to the procedure, making it possible for the procedure to determine which field was changed. The following example enables a control when a Boolean field is set to True.

   Sub Item_CustomPropertyChange(ByVal myPropName)
   Select Case myPropName
      Case "RespondBy"
         Set myPropChg = myItem.GetInspector.ModifiedFormPages
         Set myCtrl = myPropChg("Page 2").Controls("DateToRespond")
         If myItem.UserProperties("RespondBy").Value Then
            myCtrl.Enabled = True
            myCtrl.Backcolor = 1
         Else
            myCtrl.Enabled = False
            myCtrl.Backcolor = 0
         End If
      Case Else
   End Select
   End Sub

Adding a Control and an Event to a Custom Form

To add a control and an event to a custom form, follow these steps:

  1. Open a custom form.

  2. On the Tools menu in the form, click Design Outlook Form.

  3. On the Form menu in Design View, click Control Toolbox.

  4. From the Toolbox, drag the appropriate control to your form.

  5. On the Form menu, click View Code to open the Script Editor.

The Script Editor has templates for all the item events. To add an event template to your script in the Script Editor:

  1. On the Script menu, click Event.

  2. Click an event name in the list, and then click Add. The appropriate Sub...End Sub or Function...End Function statement is inserted, with its arguments (if any) specified.

    NOTE: You cannot add Click event procedures by using the Event command on the Script menu; you must type the Sub...End Sub statement for those procedures from scratch.

  3. When you are finished in the Script Editor, click Close on the File menu to return to your form.

  4. On the Tools menu, click Design Outlook Form to switch out of Design view.

    NOTE: If the Script Editor detects an error in your code, it will display a message at this point.

  5. On the File menu, click Publish Form As, and then click Publish.

  6. On the File menu, click Close. Do not save changes when prompted.

REFERENCES

For more information about creating solutions with Microsoft Outlook 97, please see the following articles in the Microsoft Knowledge Base:

   Article-ID: Q166368
   Title     : OL97: How to Get Help Programming with Outlook

   Article-ID: Q170783
   Title     : OL97: Q&A: Questions about Customizing or
               Programming Outlook


Additional query words: OutSol OutSol97
Keywords : kbprg FmsEvnt
Version : 97
Platform : WINDOWS
Issue type : kbinfo


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: March 2, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.