在MS-Access中设置和保留Split Form数据表列的列宽

时间:2016-08-25 17:44:44

标签: forms ms-access access-vba

我在Access 2012中使用了Split Form。基本数据表视图顶部显示了底部窗格中的单个记录和表单标题。

我正在尝试确定是否有办法将列宽保持为手动调整宽度 - 理想情况下,在加载窗体时,通过VBA代码将列宽设置为BestFit。

我发现this one hack会在下次开始时记住列宽。

  

我遇到了同样的问题。什么对我有用(Access 2010 Split Form)   是调整所有列的大小(通过拖动的右边缘)   列标题)我想要的方式,然后右键单击任何列标题   并选择“隐藏列”。隐藏任何列,单击“确定”,然后单击鼠标右键   再次在任何列上,选择“取消隐藏列”并取消隐藏您隐藏的列   首先。单击“确定”,然后打开表单   每次调整列宽。

但如果我分发数据库,​​问题又会再次发生。

如果我能以某种方式引用数据表视图列对象,我可能会应用BestFit方法

  

编辑 - 更新:我尝试使用此功能无效:

For Each ctl In Me.Controls
   With ctl 
      Select Case .ControlType
         Case acTextBox
            Debug.Print .Name
            If Not .ColumnHidden Then
               .ColumnWidth = -2
            End If
      End Select
  End With
Next

2 个答案:

答案 0 :(得分:3)

Unfortunately, "Me.[Field1].ColumnWidth = -2" does not work for split view.

This bizarre series of steps appears to be the only way to save column widths in an MS Access (2007-2013) "split form":

  1. In split view, set your columns widths on the datasheet side of the form. Double-click on the right edge of any column if you want to set it to the current Best Fit (unfortunately even "Best Fit" will be saved as a static width).
  2. Highlight the columns with widths you want to save. If you are doing all of them, do not use Select-All; select the first column header, then shift-click on the last column header.
  3. Right-click on the center of any highlighted column header, then click Hide Fields. All of your columns should disappear. Don't worry, this is supposed to happen.
  4. Under the Home menu tab, click on More > Unhide Fields, and select all of the columns.
  5. Hit Save, then go into Design view, and hit Save again. Your column widths will be saved.

答案 1 :(得分:0)

你没有在表单中尝试过这种方法吗? -2最适合的地方。注意:如果没有[]括号,它将不起作用。

Private Sub Form_Load()
    Me.[Field1].ColumnWidth = -2
    Me.[Field2].ColumnWidth = -2
End Sub