如何在VBA Access 2010中的“最适合”中设置所有列宽度

问题描述 投票:0回答:1

我知道设置列宽最适合具有“标题”名称的字段,下面的代码可以工作:

Private Sub Form_Load()

Forms![Contacts]![Title].ColumnWidth = -2

End sub

数据表视图中的所有列的解决方案是一行还是两行VBA代码?

非常感谢 ...

vba ms-access-2010
1个回答
0
投票
Dim f As Object
Set f = Forms![Contacts]
' Or Set f = Me.Form

Dim c As Control
For Each c In f.Controls

    With c

        ' If textbox
        If .ControlType = acTextBox Then

            ' Adjust to best fit width
            .ColumnWidth = -2
        End If
    End With
Next c

Set c = Nothing
Set f = Nothing
© www.soinside.com 2019 - 2024. All rights reserved.