Microsoft KB Archive/181216: Difference between revisions

From BetaArchive Wiki
m (Text replacement - ">" to ">")
m (Text replacement - """ to """)
 
Line 94: Line 94:
# Right-click ListBox2, and click Properties in the shortcut menu.
# Right-click ListBox2, and click Properties in the shortcut menu.
# Click the Value tab, and then click New.
# Click the Value tab, and then click New.
# In the Name box, type "IsBound" (without the quotation marks), and then click OK.
# In the Name box, type "IsBound" (without the quotation marks), and then click OK.
# In the "Property to use" list, make sure Value is selected.
# In the "Property to use" list, make sure Value is selected.
# In the Possible values box, type "0;1;2;3" (without the quotation marks), and then click OK. You have bound the ListBox2 control to the possible values of zero through three.
# In the Possible values box, type "0;1;2;3" (without the quotation marks), and then click OK. You have bound the ListBox2 control to the possible values of zero through three.


=== Creating the Form VBScript ===
=== Creating the Form VBScript ===
Line 106: Line 106:


         ' Sets ctl to the P.2 page of the form.
         ' Sets ctl to the P.2 page of the form.
         Set ctl = Item.GetInspector.ModifiedFormPages("P.2")
         Set ctl = Item.GetInspector.ModifiedFormPages("P.2")


         ' Sets ListBox1 equal to the ListBox on the control.
         ' Sets ListBox1 equal to the ListBox on the control.
         Set ListBox1 = ctl.controls("ListBox1")
         Set ListBox1 = ctl.controls("ListBox1")


         ' Loop to populate Listbox with values.
         ' Loop to populate Listbox with values.
Line 119: Line 119:


       Sub ListBox1_click()
       Sub ListBox1_click()
         MsgBox "ListBox1 Click event fired."
         MsgBox "ListBox1 Click event fired."
       End Sub
       End Sub


       Sub ListBox2_click()
       Sub ListBox2_click()
         MsgBox "ListBox2 Click event fired."
         MsgBox "ListBox2 Click event fired."
       End Sub
       End Sub


       Sub Item_CustomPropertyChange(ByVal myPropName)
       Sub Item_CustomPropertyChange(ByVal myPropName)
         MsgBox "CustomPropertyChange event fired."
         MsgBox "CustomPropertyChange event fired."
         Select Case myPropName
         Select Case myPropName
             Case "IsBound"
             Case "IsBound"
               MsgBox "Code related to field changing goes here."
               MsgBox "Code related to field changing goes here."
             Case Else
             Case Else
           MsgBox &quot;<<Select Case Else>>&quot;
           MsgBox "<<Select Case Else>>"
         End Select
         End Select
       End Sub
       End Sub

Latest revision as of 11:52, 21 July 2020

Article ID: 181216

Article Last Modified on 5/23/2002



APPLIES TO

  • Microsoft Outlook 98 Standard Edition



This article was previously published under Q181216

SUMMARY

When creating a custom Outlook 98 form, if you bind controls such as the ListBox, CheckBox or OptionButton, the click event in Visual Basic Scripting Edition (VBScript) does not fire. When these controls are not bound, however, the click event is fired.

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:

When designing Outlook forms, you typically bind a control to a field so that the value in the control is preserved when the item is saved, posted, or sent. To bind a control to a field, follow these steps:

  1. Right-click the control, and click Properties in the shortcut menu.
  2. Click the Value tab.
  3. To bind the control to an existing field, click Choose Field. -or- To bind the control to a new field, click New.

The click event for controls is the only control event Outlook supports. Using the click event, you can trigger VBScript code to run when a user clicks on a control on the form.

The Click event is often used with command buttons so a specific task can be executed via VBScript code when the user clicks a command button.

NOTE: In addition to using command buttons to trigger a VBScript event, you can also use command buttons to display built-in dialog boxes. On a message-type form, for example, command button controls can be bound to a mail field, such as To, CC, or BCC, and the Select Names dialog box appears when the button is clicked. On a custom contact form, the command button can be bound to the Categories, Check Address, or Check Name dialog boxes that are ordinarily available for a contact form. In all of these cases, the appropriate dialog boxes will be displayed without writing VBScript code.

Controls other than the command button and label usually allow users to enter information or select an option. These types of controls are typically bound to a field. In these cases, you should use either the Item_PropertyChange() event or the Item_CustomPropertyChange() event, depending on whether the control is bound to a standard Outlook field or a user-defined field, respectively. These events will fire because the value of the underlying field is being changed.

For more information about working with the PropertyChange and CustomPropertyChange events, please see the following article in the Microsoft Knowledge Base:

180857 OL98: Supported Outlook Forms Control Events


The following sample form demonstrates the click event with a bound and an unbound ListBox control:

Creating the Form and Controls

  1. Create a new e-mail message. On the message Tools menu, point to Forms, and then click Design This Form.
  2. Click the (P.2) tab. On the Form menu, click Display This Page.
  3. On the Form menu, click Control Toolbox. The Toolbox should appear.
  4. Using the Control Toolbox, place two ListBox controls and one CommandButton control on the form. Use the default names: ListBox1, ListBox2, and CommandButton1.

Making ListBox2 Bound

  1. Right-click ListBox2, and click Properties in the shortcut menu.
  2. Click the Value tab, and then click New.
  3. In the Name box, type "IsBound" (without the quotation marks), and then click OK.
  4. In the "Property to use" list, make sure Value is selected.
  5. In the Possible values box, type "0;1;2;3" (without the quotation marks), and then click OK. You have bound the ListBox2 control to the possible values of zero through three.

Creating the Form VBScript

  1. On the form's Form menu, click View Code.
  2. In the Script Editor, type the following VBScript code:

          Sub CommandButton1_Click()
    
             ' Sets ctl to the P.2 page of the form.
             Set ctl = Item.GetInspector.ModifiedFormPages("P.2")
    
             ' Sets ListBox1 equal to the ListBox on the control.
             Set ListBox1 = ctl.controls("ListBox1")
    
             ' Loop to populate Listbox with values.
             For i = 0 To 3
                ListBox1.AddItem cstr(i)
             Next
    
          End Sub
    
          Sub ListBox1_click()
             MsgBox "ListBox1 Click event fired."
          End Sub
    
          Sub ListBox2_click()
             MsgBox "ListBox2 Click event fired."
          End Sub
    
          Sub Item_CustomPropertyChange(ByVal myPropName)
             MsgBox "CustomPropertyChange event fired."
             Select Case myPropName
                Case "IsBound"
                   MsgBox "Code related to field changing goes here."
                Case Else
              MsgBox "<<Select Case Else>>"
             End Select
          End Sub
                            
  3. Close the Script Editor. On the Form menu, click Run This Form.

When you click CommandButton1, ListBox1 populates with the numbers 0 through 3. ListBox2 is already bound to the values 0 through 3. If you click a value from ListBox1, you receive a message box from the click event subroutine. If you click a value from ListBox2, the click event for ListBox2 does not execute, but the CustomPropertyChange event subroutine does execute.

REFERENCES

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

180826 OL98: Resources for Custom Forms and Programming


182349 OL98: Questions About Custom Forms and Outlook Solutions



Additional query words: OutSol OutSol98

Keywords: kbhowto kbprogramming kbdtacode KB181216