How to autosize columns in datasheet view from code

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I did not find any solution for the problem mentioned in subject.

Thank's for your help

Gabor
 
Gabor

See if this works.

' Untested code
SendKeys "%B", False
DoCmd.RunCommand.acCmdColumnWidth

In theory this should (might) cause the current column of a datasheet to
autosize as if you did Format | Column Width | Best Fit from the access
menu. Normaly I do nbot care to use the SendKeys Command, but I can't see
any other way to do this. The way it works is to jam a Control B into the
keyboard buffer and immediately invoke the menu option Format | Column
Width. Good luck.

Ron W
 
A quick search on GoogleGroups would have resulted in a solution.

From: Stephen Lebans
([email protected])
Subject: Re: Locking column widths at Datasheet form view


View this article only
Newsgroups: comp.databases.ms-access
Date: 2004-10-28 16:12:36 PST


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.
 
Thank You Stephen!

I tought this forum is the best place to ask these kind of questions.
In the meantime I'have found those hidden properties myself as well.
Unfortunatelly they are almost hidden in the help too.
The funny thing is that the columnwidth topic (in help) says that there are
two possible values for the property: 0 (hides the column); 1 (default
width). But the example at the and of the topic uses a value of -2 which I
need, because it resizes the column to fit.

Gabor

G
 
Back
Top