Code Examples

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 ********************

© 1998 - 2011 Terry Wickenden TKW Design Site developed maintained and hosted by TKW Design. This site is best viewed at 1024 x 768. Optimised for Firefox.