Share via

columnwidth= -2

Anonymous
2010-11-03T21:59:52+00:00

I would like to programically my form's (datasheet) colums to fit (expand/contract) the contents of my column.  Currently I have a form with several subforms and I'm attempting to use the code (see below) to do this.   When I use the breakpoint feature and pause the code I can hover over these lines of code and see where VBA is altering the column width.  But for instance, me.DOR (a date field) is always set at a column width of 1140 in spite of the fact that after my code runs, there is about 10 characters of space left.  What confuses me is that some of the columns are altered while others appear to not be altered enuf.  Any thoughts on what I am missing here?

OnLoad EP

Me.EEid.ColumnWidth = -2 (vba hover button states 1440)

Me.EEName.ColumnWidth = -2 (vba hover button states 1845)

Me.DOR.ColumnWidth = -2 (vba hover button states 1140)

Me.Overall.ColumnWidth = -2 (vba hover button states 540)

Me.MgrID.ColumnWidth = -2 (vba hover button states 1440)

Me.Dirid.ColumnWidth = -2 (vba hover button states 1440)

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

5 answers

Sort by: Most helpful
  1. Anonymous
    2010-11-04T15:35:57+00:00

    Glad you got it working and I see others have chimmed in with suggestions...


    --

    Gina Whipp

    2010 Microsoft MVP (Access)

    Please post all replies to the forum where everyone can benefit.

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2010-11-04T13:48:46+00:00

    Gina,

    Using -2 adjusts the column width to the best fit.  This link is where I got the idea (http://msdn.microsoft.com/en-us/library/aa224081).  It shows the -2 but does not elaborate - my curiosity did the rest.  Anyway, I've used this code elsewhere in my application and it works fine.  Out of frustration I copy/paste the fields that did work and simply renamed them over the ones that didn't.  Now my codes works and the column widths are adjusted properly.  It wasn't an elegant way of solving the problem but it now works.

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2010-11-04T12:54:14+00:00

    Zac,

    I haven't used in quite some time, but if I remember correctly, the -2 is correct.

    It should autosize the columns, just as if you did it manually.

    However, it only works on the visible columns and rows. So if the column (or row) in question is not fully visible, it won't be autosized.

    HTH

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2010-11-04T11:03:41+00:00

    Hi Zac,

    From memory, you can't do it programmatically - only through the UI. I ended up writing a complex API-driven procedure to do it.

    "Zac_Mason" wrote in message news:*** Email address is removed for privacy *** .com...

    I would like to programically my form's (datasheet) colums to fit (expand/contract) the contents of my column.  Currently I have a form with several subforms and I'm attempting to use the code (see below) to do this.   When I use the breakpoint feature and pause the code I can hover over these lines of code and see where VBA is altering the column width.  But for instance, me.DOR (a date field) is always set at a column width of 1140 in spite of the fact that after my code runs, there is about 10 characters of space left.  What confuses me is that some of the columns are altered while others appear to not be altered enuf.  Any thoughts on what I am missing here?

    OnLoad EP

    Me.EEid.ColumnWidth = -2 (vba hover button states 1440)

    Me.EEName.ColumnWidth = -2 (vba hover button states 1845)

    Me.DOR.ColumnWidth = -2 (vba hover button states 1140)

    Me.Overall.ColumnWidth = -2 (vba hover button states 540)

    Me.MgrID.ColumnWidth = -2 (vba hover button states 1440)

    Me.Dirid.ColumnWidth = -2 (vba hover button states 1440)


    Regards, Graham R Seach Sydney, Australia

    Was this answer helpful?

    0 comments No comments
  5. Anonymous
    2010-11-04T00:34:47+00:00

    The column width property is 0 to 22.  I don't see how it's doing anything at all...  What do you mean to happen with the -2?


    --

    Gina Whipp

    2010 Microsoft MVP (Access)

    Please post all replies to the forum where everyone can benefit.

    Was this answer helpful?

    0 comments No comments