Sub ToggleControl(frm As Form)
Dim ctl As Control
Dim intI As Integer, intCanEdit As Integer
Const conTransparent = 0
Const conWhite = 16777215
For Each ctl in frm.Controls
With ctl
Select Case .ControlType
Case acLabel
If .SpecialEffect = acEffectShadow Then
.SpecialEffect = acEffectNormal
.BorderStyle = conTransparent
intCanEdit = True
Else
.SpecialEffect = acEffectShadow
intCanEdit = False
End If
Case acTextBox
If .SpecialEffect = acEffectNormal Then
.SpecialEffect = acEffectSunken
.BackColor = conWhite
Else
.SpecialEffect = acEffectNormal
.BackColor = frm.Detail.BackColor
End If
End Select
End With
Next ctl
If intCanEdit = IFalse Then
With frm
.AllowAdditions = False
.AllowDeletions = False
.AllowEdits = False
End With
Else
With frm
.AllowAdditions = True
.AllowDeletions = True
.AllowEdits = True
End With
End If
End Sub作者: ACMAIN_CHM 时间: 2009-2-20 20:28
什么是'单元格'? EXCEL 还是 ACCESS ? ,你用了datagrid 控件?
''锁定/解除 窗体上主体节上所有已绑定的控件的可编辑性
''参数 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
End Function
我运行了一下,报错说,非法使用Me作者: Henry D. Sy 时间: 2009-2-27 20:39
For Each Ctl In Frm.Controls作者: jun_er 时间: 2009-2-27 21:43
还是不行。。。根本没有locked。。作者: jun_er 时间: 2009-2-27 22:21
Public Function TextLocked()
On Error Resume Next
For Each Ctl In Frm.Controls
With Ctl
Select Case .ControlType
Case acCheckBox
.Enabled = False
Case acComboBox
.Enabled = False
Case acCommandButton
.Enabled = False
Case acListBox
.Enabled = False
Case acOptionButton
.Enabled = False
Case acTextBox
.Enabled = False
End Select
End With
Next Ctl
End Function
麻烦大家再帮我看看吧,我又修改了一下,可是还是不行,窗体里的都可以编辑,就是说enable = false没有设置成功。。。不知道问题出在哪里啊。。作者: Henry D. Sy 时间: 2009-2-28 07:35
为什么不传例子,让人在这里猜谜语吗?作者: jun_er 时间: 2009-3-2 20:40 本帖最后由 jun_er 于 2009-3-3 20:33 编辑
For Each Ctl In frm.Controls
With Ctl
Select Case .ControlType
Case acCheckBox
.enabled = False
Case acComboBox
.enabled = False
Case acCommandButton
.enabled = False
Case acListBox
.enabled = False
Case acOptionButton
.enabled = False
Case acTextBox
.enabled = False
End Select
End With