Set Column Width - VBA

santosm
3StarLounger
Posts: 253
Joined: 19 Apr 2010, 09:01
Location: Indiana, USA

Set Column Width - VBA

Post by santosm »

Hi All,
I want to change the column widths of the combo box on a form based on conditions. I currently have what is below but it appears not to like it. I am sure my syntax is screwed up.

Code: Select all

        Me.Combo6.Columns(1).ColumnWidth = 0
        Me.Combo6.Columns(2).ColumnWidth = 0.75
        Me.Combo6.Columns(3).ColumnWidth = 2.5
        Me.Combo6.Columns(4).ColumnWidth = 1.3
        Me.Combo6.Columns(5).ColumnWidth = 0.5
        Me.Combo6.Columns(6).ColumnWidth = 1
        Me.Combo6.Columns(7).ColumnWidth = 1
        
Thanks,
Mark
Thanks,
Mark

santosm
3StarLounger
Posts: 253
Joined: 19 Apr 2010, 09:01
Location: Indiana, USA

Re: Set Column Width - VBA

Post by santosm »

I found that it wants Me.Combo6.Column(1).ColumnWidth = 0 instead but now it gives me an Object required error when it runs. Any ideas???
Thanks,
Mark

User avatar
HansV
Administrator
Posts: 78531
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Set Column Width - VBA

Post by HansV »

You have to set the ColumnWidths (with an "s") property of the combo box to a string that specifies the width of all columns:

Me.Combo6.ColumnWidths = "0 in; 0.75 in; 2.5 in; 1.3 in; 0.5 in; 1 in; 1 in"

As you see, we specify a semi-colon delimited list of column widths. If you don't mention the unit, Access uses twips, where 1440 twips = 1 inch. Other units must be mentioned explicitly: in for inches, cm for centimeters, or pt for points, where 72 points = 1 inch.
Best wishes,
Hans

santosm
3StarLounger
Posts: 253
Joined: 19 Apr 2010, 09:01
Location: Indiana, USA

Re: Set Column Width - VBA

Post by santosm »

Very cool! Thanks!
Thanks,
Mark