Forum Discussion
ColumnHidden Property - Doesnt seem to hide
Here's a full Function.
Public Function DataSheetControls(ByRef frm As Form) As Variant
'---------------------------------------------------------------------------------------
' Procedure : DataSheetControls
' Author : GPC Data
' Date : 9/25/2010
' Purpose :
'---------------------------------------------------------------------------------------
On Error GoTo errHandler
Dim ctl AS Control
For Each ctl In frm.Controls
If ctl.Tag = "Hidden" Then
If ctl.ColumnHidden = False Then ctl.ColumnHidden = True
ElseIf ctl.Tag = "Fixed" Then
ctl.ColumnWidth = -2 ' -2 sets column width to fit displayed text exactly
End If
Next ctl
frm.RowHeight = 0.1667 * 1440 ' set rows to default height
exitProc:
Exit Function
errHandler:
MsgBox Err & " " & Err.Description
Resume Cleanup
End Function
Call it like this:
Private Sub Form_Current()
Call DataSheetControls(Me)
End Sub
- Tony2021Jan 01, 2022Steel Contributor
Hi George,
thank you. I seem to get a 'label not defined" msg box on RESUME CLEANUP.
I put the code in my module and calling from the current event on the form as detailed above.
Let me know if I am not following.
thanks!
- George_HepworthJan 01, 2022Silver ContributorYou could experiment a bit with the syntax (one of the best trouble-shooting methods I know), although I did miss cleaning that up when I redacted the full procedure to remove some unnecessary elements for this example. The name of the label is exitProc:, not Cleanup
- Tony2021Jan 01, 2022Steel Contributor
Hi George. Thank you for the correction. Question: Is the code suppose to hide certain fields or applies to all fields that are hidden (rt clicked field and chose hide).
I need to hide only 1 field on my split form. I think I am doing something wrong but from what I have read all you do is make a button and put the below code on it. I thought maybe my form was corrupted and I created another form and put 2 buttons on it (1 for hide, 1 for unhide) with the code but nothing happens. The field doesnt hide or unhide even after I manually assign it as hidden by rt click thinking its something to do with the initial setting when form opens.
What do you think I am doing wrong? The below code seems simple enough so I narrow it down to how I am using it or there is something missing. Can you create a form and hide unhide with the below code?
Private Sub txthide_Click()
Me.txtProjectName.ColumnHidden = True
End SubPrivate Sub txtUnhide_Click()
Me.txtProjectName.ColumnHidden = False
End Sub