VBA: How go I get the total width from all controls in an Access form?

Posted by Stefan Åstrand on Stack Overflow See other posts from Stack Overflow or by Stefan Åstrand
Published on 2010-04-18T12:02:14Z Indexed on 2010/04/18 12:03 UTC
Read the original article Hit count: 385

Filed under:
|
|
|
|

Hi,

This is probably very basic stuff, but please bear in mind I am completely new to these things.

I am working on a procedure for my Access datasheet forms that will:

  1. Adjust the width of each column to fit content
  2. Sum the total width of all columns and subtract it from the size of the window's width
  3. Adjust the width of one of the columns to fit the remaining space

This is the code that adjusts the width of each column to fit content (which works fine):

Dim Ctrl As Control
Dim Path As String
Dim ClmWidth As Integer

'Adjust column width to fit content
For Each Ctrl In Me.Controls
    If TypeOf Ctrl Is TextBox Then
        Path = Ctrl.Name
        Me(Path).ColumnWidth = -2
    End If
Next Ctrl

How should I write the code so I get the total width of all columns?

Thanks a lot!

Stefan

© Stack Overflow or respective owner

Related posts about vba

Related posts about access