Show and Hide Columns on a SubForm
acCmdHideColumns, acCmdDesignView, acCmdUnhideColumns, acCmdFormView
This example assumes that you are using a subform displayed in datasheet view. It will display or hide a column on a subform control called subTestForm. It does use a bit of a work around to get the subform displayed in form view so that you can unhide the columns. You have to go into design view for the main form in order to update the subform columns.
'***************** Code Start *******************
' Code by Terry Wickenden
Private Sub cmdHideColumn_Click()
Dim strForm As String
If cmdHideColumn.Caption = "Hide Column" Then
Me.subTestForm.SetFocus
DoCmd.RunCommand acCmdHideColumns
cmdHideColumn.Caption = "Unhide Columns"
Else
DoCmd.Echo False
cmdHideColumn.Caption = "Hide Column"
strForm = Me.subTestForm.SourceObject
DoCmd.RunCommand acCmdDesignView
DoCmd.OpenForm strForm, acFormDS
DoCmd.RunCommand acCmdUnhideColumns
DoCmd.Close
DoCmd.RunCommand acCmdFormView
DoCmd.Echo True
End If
End Sub
'****************** Code End ********************