Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Datasheet view Lock? 1

Status
Not open for further replies.

Javamahn

Technical User
Mar 14, 2001
143
US
Is it possible to lock the column width on a subform that is in datasheet view?
 
Do you mean you want to prevent the user from resizing the column? Why would you want to do that?

Or do you mean you want to set the column width in design mode? You can do that by opening the subform in design view, adjusting the datasheet column widths, and saving the form design. Rick Sprague
 
Rick:

I have tried in the past to modify the column widths of a datasheet view in design mode but it seems they always default to another size (and butt up against one another). Is the default width defined in the table design?

Is there a way, other than resizing the field in table design, to force Access to use a different size with datasheet view?

The only way I have found around this is to use continuous form.

Thanks.
Larry De Laruelle
larry1de@yahoo.com

 
Umm, Larry, I've got egg on my face. I should have tried it out before I posted.

You can set the initial sizes of datasheet columns, but you don't do it in design mode, and there are no accessible properties to do it in code. What you do is open the subform in Datasheet View, change the column widths, and then save the form.

I tried it out in both Access 97 and Access 2000. In A2K, you can also adjust the column widths of the subform while it's displayed in the main form, and save the main form, and it works. I didn't have a handy main form/subform to test this with in A97, but I'll bet it works there too. Rick Sprague
 
Hi Guys!
It's "codeable" just very obscure, so stop picking on yourself Rick :)

(Most of the world wants the ability to move the widths anyway I guess....)

From Access Help:
RowHeight, ColumnWidth Properties Example

The following example changes the row height in Datasheet view of the Customers table to display two lines of data (450 twips) and sets the width of the Address column to 1.5 inches (2160 twips). These property settings will take effect the next time the Customers table is opened in Datasheet view.

To set the RowHeight and ColumnWidth properties, the example uses the SetTableProperty procedure, which is shown in the example for the DatasheetFontItalic and DatasheetFontUnderline properties, and the SetFieldProperty procedure, which is shown in the example for the ColumnHidden property.

Dim dbs As Object, tdfCustomers As Object
Const DB_Long As Long = 4
Const DB_Integer As Integer = 3
Set dbs = CurrentDb
Set tdfCustomers = dbs![Customers]
SetTableProperty tdfCustomers, "RowHeight", DB_Long, 450
SetFieldProperty tdfCustomers![Address], "ColumnWidth", DB_Integer, 2160

The next example takes effect in Datasheet view of the open Customers form. It sets the row height to 450 twips and sizes the column to fit the size of the visible text.

Forms![Customers].RowHeight = 450
Forms![Customers]![Address].ColumnWidth = -2

Wack of stuff to absorb... I can't find a way to lock a column or find an event if it was moved to put it back. Mr. Gates?
Being the "case" that I am, I hate these things, I hate these things... I never use them and am with Larry that the only way to have "real control" is to make a continuous form. If you really like the look of the sharp grid of a datasheet you can pull off a lookalike pretty well with just a bit of effort. Bingo! :) Gord
ghubbell@total.net
 
Geez, Gord, I'm impressed!

It's been evident all along that you spend all your waking hours monitoring Tek-Tips (you regularly respond to new posts before I've even finished reading them), but I had assumed you sleep at night. It's obvious now that you spend those slack hours reading example code in great detail! :) Rick Sprague
 
Thanks Rick but one question:
What does sleep mean? ;-) Gord
ghubbell@total.net
 
Gord and Rick:

Rick's suggestion for modifying the field width in datasheet view was one of those "duhs". Do it all the time when displaying query results; don't know why it didn't dawn on me to try it with a sub form.

Gord's right, trying to manipulate the datasheet view with code seems to be a lot more work than it is worth. Gord, if you get Bill's attention, something like the column size settings for a combo box would be a nice feature for sizing datasheet view columns.

In the meantime, I'll stick with continuous for my sub forms. My only complaint is with check boxes but that's not a biggee.

Thanks guys for all the tips I've picked up from you two and all the other posters.
Larry De Laruelle
larry1de@yahoo.com

 
Thanks Larry. :) And for your posts too! Now tell me what's your "beef" with check boxes? I'm curious.... X-) Gord
ghubbell@total.net
 
Gord:

Just don't like the way they line up and display. If I try to center them in the row they force the overall row height wider than the other fields. This, of course, leave blank space between rows unless I make the other fields fatter which doesn't look so good either.

Small thing and it doesn't seem to bother my users as much as it does me.


Larry De Laruelle
larry1de@yahoo.com

 
Right. Understand 110%. Here's how to woop it: first make sure the actual frame of the check is just a spec larger than the check.. click to select it and hold down the ctrl key while you size it. By doing this it won't keep clicking down in size to the next increment in your grid. This is the key...the ctrl key. Pick the check box up by the top left corner hold the ctrl key and put it exactly where you want it. This works for any control. In a continuous form say with 6 fields and a check box I'll usually select all, align to top, size to tallest (or shortest), horizontal spacing equal, then release and go after the check all on its own as above. I can see you smiling... :) Gord
ghubbell@total.net
 
Gord:

You da' Man! ! !

Just love it when I learn new trick.

Thanks.
Larry De Laruelle
larry1de@yahoo.com

 
Thanks again Larry! Always my pleasure! :)
Gord
ghubbell@total.net
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top