Hooking Up Form Region Controls

You need to hook up the form region controls so that you can handle the control events. Outlook 2007 calls BeforeFormRegionShow, passing a reference to the form region. This is where you will hook up the controls.

1. In the main menu click Project, and then click Add Reference.

2. In the COM tab of the Add References dialog box, select Microsoft Forms 2.0 Object Library. This action adds a reference to Microsoft.vbe.Interop.Forms.

3. Add the Imports Microsoft.vbe.Interop.Forms statement to the top of the class.

4. Add the code in Listing 14.39 after the class declaration, adding fields to store a reference to the form region controls. These fields are declared WithEvents to enable you to handle the events.

Listing 14.39. Adding form region fields

Dim WithEvents TextBox1 As Outlook.OlkTextBox

Dim WithEvents CommandButton1 As Outlook.OlkCommandButton

Dim WithEvents UserForm As UserForm

5. Implement BeforeFormRegionShow by adding the code in Listing 14.40. In this function you hook up form region controls to the local fields you created in step 4.

Listing 14.40. Hooking up the form region controls

Public Sub BeforeFormRegionShow( _

ByVal FormRegion As FormRegion) _

Implements _FormRegionStartup.BeforeFormRegionShow

' Hold a reference to the user form. UserForm = FormRegion.Form

' Map the form region controls to the local variables. TextBox1 = UserForm.Controls.Item("TextBox1") CommandButton1 = UserForm.Controls.Item("CommandButton1")

End Sub

0 0

Post a comment