Special Edition Using Microsoft Office Outlook 2003
All the information described in this chapter can be put together to create a robust custom form. In this "Improving Your Outlook" section, we'll build a custom form that enables a sales department to enter an order for a retail store. When the order is entered, a task is created, reminding the user to ship the order. Because this is a retail order, it must probably be sent to a fulfillment department. This requirement dictates that a message form serve as the base message class for the custom form. Launch the message form in design mode by choosing Tools, Forms, Design a Form and choosing the Message Form from the standard forms library. The first step is to decide whether you'll have two separate modes; that is, both compose mode and read mode. If you choose to have only one mode, select Form, Separate Read Layout to merge the two modes. Now add the various controls and fields to your form. After you add the controls and fields to your form, it will look similar to Figure 32.31. Figure 32.31. The order form with controls and fields added.
After you add all your fields and controls to your form, it's time to write code to create the task entry and add other advanced functionality to your form. If you want to display an image on your form corresponding to the product ordered, place an unbound image control on your form. Use the CustomPropertyChange event to change the image loaded in the image control based on the value of the Product combo box. Use the following code to change the image stored in the image control: Sub Item_CustomPropertyChange(ByVal Name) Dim objCtrl Set objCtrl = Item.GetInspector.ModifiedFormPages("Message").Controls("ProductImageCtrl") Select Case Name Case "Product" Select Case Item.UserProperties("Product") Case "Candles" Item.UserProperties("ProductImage") = "C:\Candle.jpg" Case "Candle Holders" Item.UserProperties("ProductImage") = "C:\candleholder.jpg" Case "Vase" Item.UserProperties("ProductImage") = "C:\Vase.jpg" Case "Bowl" Item.UserProperties("ProductImage") = "C:\Bowl.jpg" Case "Pitcher" Item.UserProperties("ProductImage") = "C:\Pitcher.jpg" End Select objCtrl.Picture = LoadPicture(Item.UserProperties("ProductImage")) End Select End Sub The previous code listing examines the value of the Product field and changes the value of the ProductImage field to match the Product field selection, as shown in Figure 32.32. Finally, the image control's Picture property is set to the proper image. Figure 32.32. A fully completed custom form.
Now we'll add the code to create the Task item. This code will run when the item is sent. To create the Task item shown in Figure 32.33, use the following code segment: Sub CreateTaskItem() Dim objTask Set objTask = Application.CreateItem(3) 'Create Task Item With objTask 'Set properties of Task Item .Subject = "Order: " & Item.UserProperties("Product") .DueDate = Item.UserProperties("DueDate") .Body = "Order Details" & Chr(10) & Chr(13) & "Customer: " _ & Item.UserProperties("CustomerName") & Chr(10) & Chr(13) _ & Item.UserProperties("CustomerStreet") & Chr(10) & Chr(13) _ & Item.UserProperties("CustomerCity") & ", " & Item.UserProperties("CustomerState") _ & " " & Item.UserProperties("CustomerZip") & Chr(10) & Chr(13) _ & "Quantity: " & Item.UserProperties("Quantity") .Categories = Item.UserProperties("Product") .Close 0 'Save and Close Task Item End With Set objTask = Nothing 'Set object variable to nothing End Sub Figure 32.33. Create your Task item from your custom form.
To call this code when the item is sent, use the following Item_Send code: Function Item_Send() Call CreateTaskItem End Function You can add much more code to your form, including code to ensure that all data is properly completed before the form is sent. You can add validation formulas to your form as well. You might want to require that a candle order have a quantity greater than 10 and less than 1000. You might want to limit your due date to at least four days in advance. You can perform any number of different operations with the data already stored in your form.
|