Results 1 to 4 of 4

Thread: Auto Size (XP)

  1. #1
    2 Star Lounger
    Join Date
    Jun 2001
    Location
    Virginia, USA
    Posts
    127
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Auto Size (XP)

    I have a form that displays in datasheet view so users can sort columns ascending or descending. However, when the form opens, I would like the columns to:
    1. automatically size to show the entire contents of the widest value (some values are 12 digits).
    2. freeze the first three columns
    Are there some "DoCmd.RunCommand acSomeCommands" that will do this? I can't seem to find one that works.
    As always, your assistance is appreciated,

  2. #2
    Bronze Lounger
    Join Date
    Nov 2001
    Location
    Arlington, Virginia, USA
    Posts
    1,394
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Re: Auto Size (XP)

    I don't know of any command that is equivalent of setting Column Width = "Best Fit" via menu commands. You can set the control's ColumnWidth property in code as an integer (measured in twips = 1/1440 inch); setting of 0 (zero) will hide column, setting of -1 will size column to default width. Example:

    Private Sub Form_Load()

    With Me
    .OrderID.ColumnWidth = 800 ' twips (1 in = 1440 twips)
    .CustomerID.ColumnWidth = 1000
    .EmployeeID.ColumnWidth = 1800 ' allow extra space if combo box

    .OrderID.SetFocus
    DoCmd.RunCommand acCmdFreezeColumn
    .CustomerID.SetFocus
    DoCmd.RunCommand acCmdFreezeColumn
    .EmployeeID.SetFocus
    DoCmd.RunCommand acCmdFreezeColumn
    End With

    End Sub

    This example uses generic datasheet form based on Northwind.mdb Orders table. Note that you have to specify the fields (columns) you want to size and/or freeze. Use the acCmdFreezeColumn constant to "freeze" the selected column. A form does not have a "Columns" property that I am aware of, so you have to freeze columns one at a time by setting focus to specified field, then using the freeze command.

    HTH

  3. #3
    Super Moderator
    Join Date
    Aug 2001
    Location
    Evergreen, CO, USA
    Posts
    6,623
    Thanks
    3
    Thanked 60 Times in 60 Posts

    Re: Auto Size (XP)

    Mark has suggested a solution using code, but have you considered making your form continuous rather than using the datasheet view? Users can still sort in that environment, and you can set the width of individual fields to the maximum you should ever encounter, and you can even make it double rows so users can see all the data without having to scroll. Just my <img src=/S/2cents.gif border=0 alt=2cents width=15 height=15>
    Wendell

  4. #4
    2 Star Lounger
    Join Date
    Jun 2001
    Location
    Virginia, USA
    Posts
    127
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Auto Size (XP)

    Wendell and Mark,
    Thanks. It turns out that I have reason to use both of your solutions. The continuous form view works for a human resources application that we have. When you say "double rows", Wendell, I assume that you mean that I put the first 5 fields on one "row" and then the last 4 directly under while in form design view. Each form is really only about 1/2 inch in height and spans the width of an 800x600 display with no scrolling.

    The code solution for works for the other db. In this one, we want the users to be able to see something that looks as much like an Excel spreadsheet as we can.

    Thanks,

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •