problem with ColumnHidden

M

Mark Andrews

I am trying to hide columns in a datasheet view.
If I use
Me.Controls("txtAccountID").ColumnHidden = True
it works perfectly.

Now I would like to loop through all controls and hide all of them, and then
show only 3 columns.
I tried this code with no success.

Can anyone help? (Access2003 in Access2000 format)



Private Sub Form_Open(Cancel As Integer)
Dim ctl As Control
Dim ctlname As String

'Me.Controls("txtAccountID").ColumnHidden = True
'Me.Controls("txtContactID").ColumnHidden = True

For Each ctl In Me.Controls
ctlname = ctl.Properties("Name")
ctl(ctlname).ColumnHidden = True
Next ctl

End Sub


Thanks in advance,
Mark
 
M

Mark Andrews

That's what I tried first. I get object doesn't support this property or
method on the ctl.ColumnHidden = True line

I don't see the ColumnHidden using intellisense either.

help,
Mark
 
J

John Spencer

I suspect that you have other controls on the form. They may not be visible
in datasheet view, but they are there. Those additional controls DON'T have a
columnhidden property.

Easiest solution would probably be to specifically reference the controls that
you want to hide.

John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County
 
M

Mark Andrews

Thank you for the explaination!


John Spencer said:
I suspect that you have other controls on the form. They may not be
visible in datasheet view, but they are there. Those additional controls
DON'T have a columnhidden property.

Easiest solution would probably be to specifically reference the controls
that you want to hide.

John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County
 
M

Mark Andrews

FYI: I just used this code:
On Error Resume Next
For Each ctl In Me.Controls
ctl.ColumnHidden = True
Next ctl
Me.Controls("cmbActivityType").ColumnHidden = False
Me.Controls("txtSubject").ColumnHidden = False
Me.Controls("txtAccountName").ColumnHidden = False
Me.Controls("txtContactName").ColumnHidden = False
 

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