ACC: How to Use the ColumnWidth Property

ID: Q111778

The information in this article applies to:

SUMMARY

Moderate: Requires basic macro, coding, and interoperability skills.

This article describes the ColumnWidth property, which applies to fields or columns in Datasheet view. This property is documented in the Microsoft Access Help Index.

NOTE: In Microsoft Access version 1.1, the ColumnWidth property is documented in the "The Secrets of Access Wizards" manual, which is included with the Microsoft Access Distribution Kit.

MORE INFORMATION

The ColumnWidth property applies to fields or columns in Datasheet view. It is an integer that represents the column width in twips. You can specify a width, or you can use one of the following predefined settings:

   Setting   Description
   -----------------------------------------------------------------

    0        Hides the column
   -1        Sizes the column to the default width (default setting)
   -2        Sizes the column to fit the visible text

You can also set this property by clicking the Column Width command on the Format menu (or Layout menu in Access 1.x) while in Datasheet view.

If you set a field's ColumnWidth property to 0 to hide the field, that field's ColumnHidden property is set to -1. If you set the field's ColumnHidden property to 0 to show the field, the field's ColumnWidth property is restored to the setting it had before the field was hidden. If you hide the field by setting its ColumnWidth property to 0, the ColumnWidth property is set to -1, which is the default width. Note that the ColumnWidth property for a field is not available when the field's ColumnHidden property is set to -1.

Microsoft Access evaluates the properties for a table or query in Datasheet view when the table or query is first opened in Datasheet view. If the table or query is open in Datasheet view when you change a field's ColumnWidth property by using Visual Basic (or Access Basic in Microsoft Access 2.0 or earlier), the changes will not take effect until you close and then reopen the table or query in Datasheet view.

The form can be open in any view, and changes to the ColumnWidth property will take effect immediately.

NOTE: In Microsoft Access version 1.x, in order to change the ColumnWidth property of a field on a form, the form must be open in Design view. If the form is not open in Design view, the property is read-only.

The following example demonstrates how to set the ColumnWidth property for the Customers form in Datasheet view. This setting will change the Address column's width to 1.5 inches (2160 twips):

   Forms![Customers]![Address].ColumnWidth = 2160

REFERENCES

For more information about the ColumnWidth property, search the Help Index for "ColumnWidth Property," or ask the Microsoft Access 97 Office Assistant.

Additional query words:

Keywords          : kbprg TblFldp 
Version           : 1.0 1.1 2.0 7.0 97
Platform          : WINDOWS
Hardware          : x86
Issue type        : kbhowto

Last Reviewed: November 21, 1998