ACC2000: The TextWidth Property Returns Incorrect Results

ID: Q248945


The information in this article applies to:
  • Microsoft Access 2000

Advanced: Requires expert coding, interoperability, and multiuser skills.

This article applies to a Microsoft Access database (.mdb) and a Microsoft Access project (.adp).


SYMPTOMS

When you run a report that contains code which dynamically calculates width, you notice that the calculations are incorrect.


CAUSE

The TextWidth property returns incorrect results. Consequently, any changes that you make to the report based on this property are incorrect.


STATUS

Microsoft has confirmed this to be a problem in the Microsoft products listed at the beginning of this article.


MORE INFORMATION

Steps to Reproduce Behavior

  1. In a new Access database, create the following new table:


  2. 
       Table: TestTable
       ----------------------------
       Field Name: TestID
       Data Type: AutoNumber
       Indexed: Yes (No Duplicates)
    
       Field Name: TestField
       Data Type: Text 
  3. Save the table, and then open it in Datasheet view. Enter the following data:


  4. TestID TestField
    1 1
    2 12
    3 123
    4 1234
    5 12345
    6 123456
    7 1234567
    8 12345678
  5. In the Database window, click Reports under Objects, and then click New.


  6. In the New Report box, click AutoReport: Tabular, click TestTable in the Choose the table or query where the object's data comes from box, and then click OK. The new report appears.


  7. On the View menu, click Design. Then on the View menu, click Code.


  8. Type the following code:


  9. 
    Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)
       Debug.Print "Value:'" & Me.TestField & _
         "'"; vbTab & "TextWidth:" _
         & Me.TextWidth(Me.TestField); vbTab _
         & "TextHeight:" & Me.TextHeight(TestField)
    End Sub 
  10. Return to Access and view the report in Print preview.


  11. Press CTRL+G to open the Immediate window.


In the Immediate window, you see something similar to the following output. (The actual numbers may vary from system to system because of different screen resolutions.) You would expect the TextWidth property values to increment smoothly as the width of the field increases. Instead the values appear to increase and decrease randomly:

   Value:'1'    TextWidth:629    TextHeight:158
   Value:'12'    TextWidth:254    TextHeight:158
   Value:'123'    TextWidth:302    TextHeight:158
   Value:'1234'    TextWidth:629    TextHeight:158
   Value:'12345'    TextWidth:610    TextHeight:158
   Value:'123456'    TextWidth:1003    TextHeight:158
   Value:'1234567'    TextWidth:984    TextHeight:158
   Value:'12345678'    TextWidth:1310    TextHeight:158 

Additional query words: pra wrong not right unexpected random

Keywords : kbdta
Version : WINDOWS:2000
Platform : WINDOWS
Issue type : kbbug


Last Reviewed: January 28, 2000
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.