一个锁定数据表子窗体列宽的问题。记得曾经有过一个版友提出过另外一个连续子窗体列宽调整的问题,这个问题好像一直没有很好的解决。看来这两类窗体在列宽的可调整与不可调整方面各有利弊,因此也就有版友希望能得到取长补短的办法。
今日针对kris3000同志的问题做一实例,解决数据表子窗体列宽锁定问题。关于连续子窗体列宽调整,我想也是可以解决的,只是代码要写的复杂一些。
部分代码:
Option Compare Database
Option Explicit
Dim ctlN() As String
Dim ctlW() As Single
Function ctlVal(frm As Form)
Dim ctl As Control
Dim ctls As Controls
Dim i As Long
Set ctls = frm.Controls
i = 0
For Each ctl In ctls
If ctl.ControlType <> acLabel Then
ReDim Preserve ctlN(i)
ReDim Preserve ctlW(i)
ctlN(i) = ctl.Name
ctlW(i) = ctl.ColumnWidth
i = i + 1
End If
Next ctl
End Function
Function ctllock(frm As Form, B As Boolean)
Dim ctl As Control
Dim ctls As Controls
Dim i As Long
If B = False Then Exit Function
Set ctls = frm.Controls
For i = 0 To UBound(ctlN, 1)
ctls(ctlN(i)).ColumnWidth = ctlW(i)
Next
End Function