Applies To Bound Object Frame control, Chart control, Check Box control, Combo Box control, Field object, List Box control, Option Button control, Option Group control, QueryDef object, Table field, TableDef object, Text Box control, Toggle Button control.
Description
You can use the ColumnHidden property to show or hide a specified column in Datasheet view. For example, you might want to hide a CustomerAddress field that's too wide so you can view the CustomerName and PhoneNumber fields.
Note The ColumnHidden property applies to all fields in Datasheet view and to form controls when the form is in Datasheet view.Setting
You can set the ColumnHidden property by clicking Hide Columns or Unhide Columns on the Format menu in Datasheet view.
You can also set this property by using a Long Integer value in Visual Basic to specify the following settings.Setting | Description |
True (–1) | The column is hidden. |
False (0) | (Default) The column is visible. |
See Also ColumnOrder property, ColumnWidth property, RowHeight property.
Example The following example hides the ProductID field in Datasheet view of the Products form.Forms!Products!ProductID.ColumnHidden = -1
The next example also hides the ProductID field in Datasheet view of the Products table. To set the ColumnHidden property, the example uses the ShowColumn and SetFieldProperty procedures, which are in the database's standard module.
Dim dbs As Database
Set dbs = CurrentDb
ShowColumn dbs.TableDefs!Products.Fields!ProductID, False
Sub ShowColumn(fldObject As Field, intShow As Integer)
' Set ColumnHidden property.
SetFieldProperty fldObject, "ColumnHidden", dbLong, Not intShow
End Sub
Sub SetFieldProperty(fldField As Field, strPropertyName As String, _
intPropertyType As Integer, varPropertyValue As Variant)
' Set field property without producing nonrecoverable run-time error.
Const conErrPropertyNotFound = 3270
Dim prpProperty As Property
On Error Resume Next ' Don't trap errors.
fldField.Properties(strPropertyName) = varPropertyValue
If Err <> 0 Then ' Error occurred when value set.
If Err <> conErrPropertyNotFound Then
On Error GoTo 0
MsgBox "Couldn't set property '" & strPropertyName _
& "' on field '" & fldField.name & "'", 48, "SetFieldProperty"
Else
On Error GoTo 0
Set prpProperty = fldField.CreateProperty(strPropertyName, _
intPropertyType, varPropertyValue)
fldField.Properties.Append prpProperty
End If
End If
End Sub