Freeze/UnFreeze Columns in Subform
acCmdFreezeColumn, acCmdUnfreezeAllColumns
This routine freezes the active column on a SubForm in Datasheet View or unfreezes that column. The button to change the view must also be on the Main Form not the SubForm.
This example uses a button called cmdFreeze and a subform control on the Main Form called subTestForm. It changes the caption of the button to reflect the change that will occur when clicked.
'***************** Code Start *******************
' This code was originally written by Terry Wickenden.
' It is not to be altered or distributed,
' except as part of an application.
' You are free to use it in any application,
' provided the copyright notice is left unchanged
Private Sub cmdFreeze_Click()
On Error GoTo ErrCmdFreeze
Me.subTestForm.SetFocus
If Me.cmdFreeze.Caption = "Freeze Column" Then
DoCmd.RunCommand acCmdFreezeColumn
Me.cmdFreeze.Caption = "Unfreeze Column"
Else
DoCmd.RunCommand acCmdUnfreezeAllColumns
Me.cmdFreeze.Caption = "Freeze Column"
End If
Exit Sub
ErrCmdFreeze:
Select Case Err
Case 2046
'Command not available
MsgBox "This command is not available at this time"
Exit Sub
Case Else
MsgBox Err.Number & vbCrLf & Err.Description
Exit Sub
End Select
End Sub
'****************** Code End ********************