Improving Your Outlook

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.

graphics/32fig31.jpg

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.

graphics/32fig32.gif

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.

graphics/32fig33.gif

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.

Using Redemption in VBScript Code

In the wake of the Melissa and I Love You viruses, Microsoft added new security restrictions on VBA and VBScript code in Outlook. These restrictions display warning dialogs when certain actions are performed, such as sending email programmatically and accessing the Outlook address book. If you run code within your Outlook form that accesses email addresses or sends email, the Outlook Object Model Guard will display a warning message about another program trying to access your email addresses or send email on your behalf.

Redemption uses Extended MAPI to provide "safe" objects that bypass the security prompts. Simply set a variable to one of these safe objects, and you can use it just as you would a normal Outlook object.

With the addition of only a few lines of code, you can bypass the security prompt and allow code to access the email address of a contact in your Outlook Contacts folder or send email programmatically.

One of the greatest advantages of Redemption is that changes to your code are very minimal, often requiring only two additional lines per object. After you've set your object variable to a Redemption object, all the rest of your code can remain the same.

Not only can Redemption be used with VBScript behind Outlook forms, but it can also be used with VB and VBA.

Redemption also exposes some properties that the Outlook Object Model does not. Have you ever wanted to get the sender's email address out of one of the messages in your inbox? Redemption provides a utility object that enables you to obtain the sender's email address, force the delivery of queued outgoing messages, compare two items to determine whether they're the same item, and display the address book. If you want more information about Redemption, see http://www.dimastr.com/Redemption.



Special Edition Using Microsoft Office Outlook 2003
Special Edition Using Microsoft Office Outlook 2003
ISBN: 0789729563
EAN: 2147483647
Year: 2003
Pages: 426

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net