iterate through fields in datasheet on a subform

  • Thread starter Thread starter Mike
  • Start date Start date
M

Mike

Hi,

can anyone point me at a code snippet demonstrating how I can iterate
through all columns on a datasheet in a subform (which is open) so that I
can .ColumnHidden = False. I am using Access 2000 (and have searched but
not found a solution I can use so far).

thanks

Mike
 
The exact syntax will depend on where the code is running. If it is not
running on the subform the Me will need to be replaced with the path to the
subform

Dim ctl As Control
For Each ctl in Me.Controls
On Error Resume Next
ctl.ColumnHidden = False
Next

The reason for the Error statement is that controls, such as labels and
lines, will generate an error. The other option would be to use an If
statement to verify the type of control first, then unhide it. If you use
the Resume Next and had previously set up error handling, don't forget to
reinstate the error handling.
 
Many thanks, that did the trick !

Mike
Wayne Morgan said:
The exact syntax will depend on where the code is running. If it is not
running on the subform the Me will need to be replaced with the path to the
subform

Dim ctl As Control
For Each ctl in Me.Controls
On Error Resume Next
ctl.ColumnHidden = False
Next

The reason for the Error statement is that controls, such as labels and
lines, will generate an error. The other option would be to use an If
statement to verify the type of control first, then unhide it. If you use
the Resume Next and had previously set up error handling, don't forget to
reinstate the error handling.
 
Back
Top