''锁定/解除 窗体上主体节上所有已绑定的控件的可编辑性
''参数 Frm: 窗体名
''参数 MyLocked: True锁定 / False解除
'' 使用示例:
''执行锁定: TextLocked(Me, True)
''执行解除: TextLocked(Me, False)
Public Sub TextLocked(Frm As Form, MyLocked As Boolean)
On Error Resume Next
Dim obj As String
For Each ctl In Frm.Section(acDetail).Controls '遍历主体上控件
obj = ctl.ControlSource
If IsNull(obj) Or Trim(obj) = "" Or ctl.Enabled = False Then GoTo OUT '为 未绑定数据源控件 或 不可用控件 时跳出循环下一个
If MyLocked Then
ctl.Locked = True
If ctl.ControlType = acTextBox Or ctl.ControlType = acComboBox Or ctl.ControlType = acListBox Then
If ctl.ForeColor <> 16737843 Then ctl.ForeColor = 16737843 '对文本框、组合框、列表框字体颜色更改
End If
Else
ctl.Locked = False
If ctl.ControlType = acTextBox Or ctl.ControlType = acComboBox Or ctl.ControlType = acListBox Then
If ctl.ForeColor <> 4194432 Then ctl.ForeColor = 4194432 '对文本框、组合框、列表框字体颜色更改
End If
End If
For Each Ctl In Me.Controls
If Ctl.ControlType = acTextBox Or _
Ctl.ControlType = acComboBox Or _
Ctl.ControlType = acListBox Then
Ctl.Locked = True
End If
Next Ctl