TextWidth Method

Applies To

Report Object.

Description

The TextWidth method returns the width of a text string as it would be printed in the current font of a Report object.

Syntax

object.TextWidth(strexpr)

The TextWidth method uses the following arguments.

Argument

Description

object

The Report object that determines the font and point size

strexpr

The text string for which the text width will be determined


Remarks

You can use the TextWidth method to determine the amount of horizontal space a text string will require in the current font when the report is formatted and printed. For example, a text string formatted in nine-point Arial will require a different amount of space than one formatted in 12-point Courier. To determine the current font and point size for text in a report, check the settings for the report’s FontName and FontSize properties.

The value returned by the TextWidth method is expressed in terms of the coordinate system in effect for the report, as defined by the Scale method. You can use the ScaleMode property to determine the coordinate system currently in effect for the report.

If strexpr contains embedded carriage returns, the TextWidth method returns the width of the longest line, from the beginning of the line to the carriage return. You can use the value returned by the TextWidth method to calculate the necessary space and positioning for multiple lines of text within a report.

See Also

FontName, FontSize Properties; Scale Method; TextHeight Method.

Example

The following example uses the TextHeight and TextWidth methods to determine the amount of vertical and horizontal space required to print a text string in the report’s current font.

To try this example in Microsoft Access, create a new report by clicking the New button on the Reports tab of the Database window. Set the OnPrint property of the Detail section to [Event Procedure]. Enter the following code in the report’s module, then switch to Print Preview.


Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)
    ' Set unit of measure to twips (default scale).
    Me.Scalemode = 1
    ' Print name and point size of report font.
    Debug.Print "Report Font: "; Me.FontName
    Debug.Print "Report Font Size: "; Me.FontSize
    ' Print height and width required for text string.
    Debug.Print "Text Height (Twips): "; Me.TextHeight("Product Report")
    Debug.Print "Text Width (Twips): "; Me.TextWidth("Product Report")Sub