Online Book Reader

Home Category

Access Cookbook - Ken Getz [113]

By Root 1976 0
make aren't saved with the report. If you want to permanently save the report with the new settings, you'll need to modify the code so that the report opens in design view; changes you make will then be saved with the report when you close and save it.) The following sections explain both how to use the sample form from 05-03.MDB and how to work with these properties and your own objects.

To use the sample form in your own applications, follow these steps:

Import the form frmPrintSettings into your application. This form allows you to choose from the existing reports in your database.

Once you've chosen the report (which the form will open in preview mode), you can alter print layout settings. Once you're done, you can print the report.

Discussion


The sample form for this topic does very little work—it simply copies values from the Printer property of the selected report to controls on the form, converting from twips (1/1,440 inch) to inches for display purposes. When you click Save Settings, the code writes the settings back to the appropriate properties of the report's Printer property.

Access's Printer object provides a number of properties dealing with print layout. Table 5-1 describes the subset of Printer object properties used in this example form.

Table 5-1. Printer object properties associated with print layout

Property

Comments

LeftMargin

Distance between the left edge of the paper and the object to be printed (in twips)

TopMargin

Distance between the top edge of the paper and the object to be printed (in twips)

RightMargin

Distance between the right edge of the paper and the object to be printed (in twips)

BottomMargin

Distance between the bottom edge of the paper and the object to be printed (in twips)

DataOnly

If True (-1), Access prints just data, not labels, control borders, gridlines, and display graphics; if False (0), Access prints all elements

ColumnSpacing

Distance between detail section columns (if ItemsAcross > 1), in twips

DefaultSize

If True (-1), Access uses the width and height of the design-mode detail section when printing; if False (0), Access uses the values specified in the ItemSizeWidth and ItemSizeHeight properties

ItemLayout

acPRHorizontalColumnLayout (Across, then Down), or acPRVerticalColumnLayout (Down, then Across) for multiple-columned reports

ItemSizeWidth

Width of the detail section; if the DefaultSize property is False and the ItemsAcross property is greater than 1, the width of each column (in twips)

ItemSizeHeight

Height of the detail section (read-only)

ItemsAcross

Integer that specifies the number of columns across the page for multiple-columned reports

RowSpacing

Vertical distance between detail sections (in twips)

After you select a report on the sample form, the combo box's AfterUpdate event procedure calls the following code, which opens the report in preview mode, then copies the report's properties to the controls on the form:

strReport = Me.cboReportList

DoCmd.OpenReport strReport, View:=acViewPreview

With Reports(strReport).Printer

Me.txtLeft = ToInches(.LeftMargin)

Me.txtRight = ToInches(.RightMargin)

Me.txtTop = ToInches(.TopMargin)

Me.txtBottom = ToInches(.BottomMargin)

Me.chkDataOnly = .DataOnly

Me.txtXFormSize = ToInches(.ItemSizeWidth)

Me.txtYFormSize = ToInches(.ItemSizeHeight)

Me.txtCxColumns = .ItemsAcross

Me.txtYFormSpacing = ToInches(.ItemSizeHeight)

Me.chkfDefaultSize = .DefaultSize

Me.txtXFormSpacing = ToInches(.ColumnSpacing)

Me.grpRadItemOrder = .ItemLayout

End With

Don't forget that all the measurements in the Printer object are stored in twips. The ToInches function simply divides its parameter value by 1,440 and adds the text "in." to its output value. The corresponding FromInches function does the opposite—it strips off extra text and multiplies its parameter value by 1,440 to convert back to twips. Why 1,440? A twip is defined as 1/20 of a point. There are 72 points per inch and 20 twips per point; therefore, 72 × 20 = 1,440 twips per inch.

When you click Save

Return Main Page Previous Page Next Page

®Online Book Reader