Outlook 2003 and Other Office Applications

You can use Outlook 2003 to interact with other Office applications in several different ways. One of the most common uses of Outlook/Office integration is to print custom reports or custom forms. If you've worked at all with custom forms, you know they can be very powerful. You can create multiple pages with a variety of different controls. However, printing custom forms leaves something to be desired. Simply selecting Print from the File menu produces a listing of custom and standard fields in alphabetical order. You cannot control the format of the information or the order in which it's printed. You have no choices for layout because all fields print one after the other on a separate line.

If you want to create a custom printout of your form, you can use code to transfer the information from your Outlook form to Microsoft Word or Excel.

Print a Custom Form Using Word

When users print an Outlook form for the first time, they're typically expecting WYSIWYG (what you see is what you get) printing. What they get is anything but that. The main way to print data from Outlook forms is to use a Microsoft Word template. A template can enable you to pull data from multiple applications, include graphics, formatting, or any other Microsoft Word specific features such as tables, headers, footers, and page breaks. You can control just about every aspect of printing when you use a Word document to print data from Outlook forms.

XPrint

Outlook 2000 offered one additional way to print Outlook forms, the XPrint control and add-in. This add-in, implemented as an Exchange Client Extension, allowed form pages to be printed almost exactly as they appeared on the screen. Unfortunately, this add-in hasn't been tested or approved for use with Outlook 2002 or Outlook 2003. It's still possible to use the XPrint add-in, but your results might vary. For more information about the XPrint Control and Add-in, see http://support.microsoft.com/default.aspx?scid=kb;EN-US;238778.

When using VBScript behind an Outlook form to print your form data, you must be able to reference the various fields on your form. To reference a standard field on an Outlook form, use the Item.FieldName syntax. For example, to reference the FullName field of a contact item, use Item.FullName. When referencing custom properties, use the following syntax:

 Item.UserProperties("FieldName") 

To print your Outlook form data, use the following code example. This sample prints data from the custom form shown in Figures 34.1, 34.2, and 34.3 in a Word document, as shown in Figure 34.4. Even though your custom form has three pages, you can print all the required information on one page of your Word document.

 Sub cmdPrint_Click()     Set oWordApp = CreateObject("Word.Application")   'Create Word instance     If oWordApp Is Nothing Then    'If Word doesn't start then display message         msgbox("Can't start Microsoft Word")     Else      Dim oDoc      Dim bolPrintBackground      'Open a new document      Set oDoc = oWordApp.Documents.Add("\\servername\c\Forms\Frame.dot")      'Set fields to map to template      oDoc.FormFields("OrderNumber").Result = item.userproperties("OrderNumber")      oDoc.FormFields("CustomerName").Result = item.userproperties("CustomerName")      oDoc.FormFields("CustCode").Result = item.userproperties("CustCode")      oDoc.FormFields("CreationDate").Result = item.userproperties("CreationDate")      oDoc.FormFields("SR").Result = item.userproperties("SalesRep")      oDoc.FormFields("CSR").Result = item.userproperties("CSR")      oDoc.FormFields("Status").Result = item.userproperties("Status")      oDoc.FormFields("DueDate").Result = item.userproperties("DueDate")      oDoc.FormFields("WoodStain").Result = item.userproperties("WoodStain")      oDoc.FormFields("FrameStyle").Result = item.userproperties("FrameStyle")      oDoc.FormFields("NumColors").Result = item.userproperties("NumColors")      oDoc.FormFields("Length").Result = item.userproperties("txtLength")      oDoc.FormFields("Width").Result = item.userproperties("txtWidth")      oDoc.FormFields("Coating").Result = item.userproperties("Coating")      oDoc.FormFields("Etching").CheckBox = item.userproperties("Etching")      oDoc.FormFields("Extras").CheckBox = item.userproperties("Extras")      oDoc.FormFields("Hanger").CheckBox = item.userproperties("Hanger")      oDoc.FormFields("MetalType").Result = item.userproperties("MetalType")      oDoc.FormFields("Quantity1").Result = item.userproperties("Quantity1")      oDoc.FormFields("Quantity2").Result = item.userproperties("Quantity2")      oDoc.FormFields("Quantity3").Result = item.userproperties("Quantity3")      oDoc.FormFields("Price1").Result = item.userproperties("Price1")      oDoc.FormFields("Price2").Result = item.userproperties("Price2")      oDoc.FormFields("Price3").Result = item.userproperties("Price3")      oDoc.FormFields("ShipTo1").Result = item.userproperties("ShipTo1")      oDoc.FormFields("ShipQuantity1").CheckBox = _        item.userproperties("ShipQuantity1")      oDoc.FormFields("ShipVia1").Result = item.userproperties("ShipVia1")      oDoc.FormFields("ShipTo2").Result = item.userproperties("ShipTo2")      oDoc.FormFields("ShipQuantity2").CheckBox = _       item.userproperties("ShipQuantity2")      oDoc.FormFields("ShipVia2").Result = item.userproperties("ShipVia2")      oDoc.Bookmarks("Remarks").Range.InsertAfter item.userproperties("Remarks")      bolPrintBackGround = oWordApp.Options.PrintBackground      oWordApp.Options.PrintBackground = False      oDoc.PrintOut      oWordApp.Options.PrintBackground = bolPrintBackground      wdDoNotSaveChanges = 0      oDoc.Close wdDoNotSaveChanges      oWordApp.Application.Quit      Set oDoc = Nothing      Set oWordApp = Nothing     end if End Sub 
Figure 34.1. The first page of your custom form.

graphics/34fig01.gif

Figure 34.2. The second page of your custom form.

graphics/34fig02.gif

Figure 34.3. The third page of your custom form.

graphics/34fig03.gif

Figure 34.4. A Word document can have graphics, bullets, tables, and horizontal lines.

graphics/34fig04.gif

As you can see, you use different syntax for each type of Word control you need. To send a value in an Outlook form to a check box control in Word, use the following syntax:

 oDoc.FormFields("TestReq").CheckBox = item.userproperties("chkTestReq") 

To send a large amount of data to a field on a Word document, use the following syntax:

 oDoc.Bookmarks("DesRemarks1").Range.InsertAfter _ item.userproperties("txtDesRemarks") 

After you've filled all of your fields, turn off background printing in Word and execute the PrintOut method of the Word document to print your form. When you're done, close the temporary document you created and exit Word.

TIP

If you have multiple users who need to access the form and the Word document, you can put the Word document on a network file share so that everyone can access it.




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