Code for Hidding Columns in a subform

G

Guest

I hav form containing a subform and a subdatasheet. i want to use code to
automatically hide certain columns in the subdatasheet. I tried using the
code Form_Subdatasheet.Form.Controls("ColumnName").Visible = True, but no
good. Anyone have the code that will work?

thanks,
Matt
 
K

Ken Snell [MVP]

If I recall correctly (I rarely use datasheet views in forms), you cannot
hide a column (control) in a datasheet view. You can lock and/or disable
them.

In order to be able to hide the control, use a continuous forms view instead
of a datasheet view. You can arrange the textboxes, etc. in a grid pattern
to simulate the datasheet view.
 
G

Guest

If you open the main form which contains the subform and subdatasheet, then
focus on the subdatasheet, you can go to Format, Hide or Unhide columns inthe
main toolbar. Apply your settings and then save. There must be code to
apply this. Also, when viewing many rows of data i find users requesting
datasheet view rather than form in order for the screen to appear much like
an Excel spreadsheet. This allows the user to easile select all and copy to
Excel.
 
S

Stephen Lebans

Here is a previous post of mine on this subject.


From: Stephen Lebans
([email protected])
Subject: Re: Freeze Column?
View: Complete Thread (3 articles)
Original Format
Newsgroups: microsoft.public.access.forms,
microsoft.public.access.formscoding,
Date: 2003-12-24 11:53:00 PST


For programmatic control for forms in Datasheet view my standard
response is:


1) Michael Kaplan has an excellent article on manipulating Datasheets
here:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnsmart
01/html/sa01b1.asp


2) An API solution is here:
http://www.lebans.com/autocolumnwidth.htm
The AutoSizing project also contains a method to FREEZE the
ColumnWidths.


--




--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.
 
G

Guest

Works like a charm, that site contains some real interesting methods.

Thanks alot!!!

Matt
 
K

Ken Snell [MVP]

As I said, you can arrange the textboxes in a continuous forms view to look
like a datasheet. Just make them the same size and put them right next to
each other, with the height of the Detail section the same as the height of
the textbox. Your users won't be able to resize the control's width or
height, but ...

I did some research, and it appears that you can use the RunCommand method
to hide and unhide columns exactly the same way you would do it manually via
Format menu.

To hide a column, set the focus to that column and then run the hide columns
action:

Me.ColumnName.SetFocus
DoCmd.RunCommand acCmdHideColumns

To unhide columns, run
DoCmd.RunCommand acCmdUnhideColumns

Note that the user will be asked, by a muliselect list, which columns to
unhide -- exactly the same way as it works via the menu when you do it
manually.
 
K

Ken Snell [MVP]

Thanks for reposting this info, Stephen... I learned more new things today!
< g >
 

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