programmatically hiding fields in a datasheet form

I have a subform in datasheet view with field "x" on it... and on some
event I can hide or unhide it... like this.

Me.Table1_subform.Form("x").ColumnHidden = False

But, I can't see a way to get a collection of the field names from the
record source (table) it is bound to! I want to loop through all the
fields and hide or unhide based on their names!

??????????? Any ideas?

Thanks in advance
 
B

Brendan Reynolds

Here's something I posted recently in response to a similar question. This
sets the ColumnWidth property, but you should be able to modify it to your
needs. Change the line 'ctl.ColumnWidth = -1' to something like ...

If ctl.Name = "Whatever" Then
ctl.ColumnHidden = True
End If

Private Sub Form_Load()

Dim frm As Form
Dim ctl As Control

Set frm = Me.sfrTest.Form
For Each ctl In frm.Controls
If ctl.ControlType = acTextBox Then
ctl.ColumnWidth = -1
End If
Next ctl

End Sub
 
J

John Nurick

You can get the field names by iterating Form.Recordset.Fields or
Form.RecordsetClone.Fields.

But you'll need to keep a clear head if your controls have the same
names as the fields they are bound to. It's probably a good idea to use
explicit syntax throughout, e.g.
Me.Table1_subform.Form.Controls("x").ColumnHidden
to avoid confusion between the control called x and the field called x.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top