Link to home
Start Free TrialLog in
Avatar of johnmadigan
johnmadiganFlag for United States of America

asked on

ms access hide datasheet column vba

I have a buttons on a main switchboard form.  When I click a button it opens a form with a datasheet subform.  When I click on a different button on the switchboard I want to open the same form with the same datasheet subform but hide a few colunms.  So each different button will open the same form but different columns will be showing up in the subform.

What is the  best way to handle this?  I tried a few things on the click event of the button on the switchboard but could not get the subform to have some of the colums hiddend upon opening.

Any suggestions?

Thanks,
Avatar of cyberkiwi
cyberkiwi
Flag of New Zealand image

You can hide columns by way of changing the underlying query that produces the datasheet.
So if button1 is clicked, you can set

button1 clicked : QueryDefs("qryData").SQL = "select a,b,c,d from tbl"
button2 clicked : QueryDefs("qryData").SQL = "select a,b,d from tbl"
button3 clicked : QueryDefs("qryData").SQL = "select c,d from tbl"

etc, where each click changes the columns being selected by the query behind the datasheet
I don't think it is possible to do what you want. Even if it is possible you are making life unnecessarily complicated for yourself.

Just create two forms ... each with the columns you want. (make a copy of your present one and edit it)
If you do that, you'll end up with invalid columns on the sheet and they'll show the "#Name" value. With a Datasheet you can hide the columns as needed:

Me.YourControlName.ColumnHidden = True
ASKER CERTIFIED SOLUTION
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial