I just want to hide a column in a subform

jbrandes

New Member
Joined
Dec 20, 2011
Messages
10
I'm tring to toggle the visible property of a column in a sub form based on input from a check box on the main unbound form

If Me.Check55 = True Then

'This part works fine, if checkbox 55 is true the subform filters records based on "DBSUB.[Austin] Yes or No

strWhere = strWhere & " AND " & "DBSUB.[Austin] = " & Me.Check55

'These are just a few of my attempts to hide other columns that are not needed

Me!DBSUB.Dallas.ColumnHidden = True
'Forms!DBSUB.Controls!Dallas.Visible = False
'Forms!DBSUB.Dallas.Visible = False
'Me!DBSUB(Dallas).Visible = False

'None of these work, please any suggestions?


End If
 

Some videos you may like

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,235
Office Version
  1. 365
Platform
  1. Windows
Is this subform a datasheet?
 

jbrandes

New Member
Joined
Dec 20, 2011
Messages
10
Sorry, yes the subform is a datasheet. I can hide any column I wish manually, I just can seem to do with the code.

Thanks.
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,235
Office Version
  1. 365
Platform
  1. Windows

ADVERTISEMENT

I'm pretty sure you can't do it with code.

Why do you want to hide the 'column' anyway?
 

jbrandes

New Member
Joined
Dec 20, 2011
Messages
10
The columns I want to hide are just not pertinent to the results that are displayed, Plus it make the datasheet to wide. There are acually several columns that I will be hiding based on user selections, but if I can get one to work I can get them all.

There has to be some way to make them not seen, setting the column width to 0 or something, anything.

Thanks
 

alansidman

Well-known Member
Joined
Feb 26, 2007
Messages
6,069
Office Version
  1. 365
  2. 2019
Platform
  1. Windows

ADVERTISEMENT

If you right click on the columns you want to hide in datasheet view, you will be given an option to hide the column.

Alan
 

jbrandes

New Member
Joined
Dec 20, 2011
Messages
10
Yep, I know I can do it manually, but I would like the code to handle it based on a user selection from the main form.

If this (Mainform) checkbox is checked hide that (Subform)column... Seems simple I don't know why I can't figure it out.

Thanks
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,235
Office Version
  1. 365
Platform
  1. Windows
jbrandes

As far as I know it's just not possible.

If the column(s) aren't relevant why are they shown in the datasheet anyway.
 

boblarson

MrExcel MVP
Joined
Nov 14, 2008
Messages
1,964
jbrandes

As far as I know it's just not possible.

SURPRISE! Actually, it is possible.

Here's a nice article on what you can do with Datasheets:
http://msdn.microsoft.com/en-us/library/aa217449(office.11).aspx

And the property that should be used is

ColumnHidden

So, if this didn't work:

Me!DBSUB.Dallas.ColumnHidden = False

then the problem may be

1. Referring to the subform instead of the subform CONTROL which is what should be used.

2. Referring to the FIELD instead of the CONTROL which should be used.


@jbrandes - For Subforms you must refer to the subform control (control on the subform which HOUSES the subform on the parent form) and NOT the subform name itself UNLESS the subform control and the subform are named the EXACT same.

So,

Me.SubformControlNameHere.Form.TextBoxNameHere.ColumnHidden = True

would be the correct syntax.
 

Watch MrExcel Video

Forum statistics

Threads
1,123,518
Messages
5,602,138
Members
414,505
Latest member
quoctrungvu99

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top