是否可以在 ACCESS 2007 的表单中使所有其他字段成为只读字段时保持可编辑状态?我的表单上有大约 40 个控件,让它们一一读取会很不方便。我希望这些字段之一(选项组)可编辑,以便当用户选择一个选项时,整个表单变得可编辑
问问题
7210 次
2 回答
1
选项1
您可以将要锁定的表单设置为子表单并将选项组放在主表单中:
例如:
Private Sub Form_Current()
Me.aTable_subform.Form.AllowAdditions = False
Me.aTable_subform.Form.AllowEdits = False
Me.aTable_subform.Form.AllowDeletions = False
End Sub
Private Sub PickOne_AfterUpdate()
Select Case Me.PickOne
Case 1, 3
Me.aTable_subform.Form.AllowAdditions = True
Me.aTable_subform.Form.AllowEdits = True
Me.aTable_subform.Form.AllowDeletions = True
Case 2
Me.aTable_subform.Form.AllowAdditions = False
Me.aTable_subform.Form.AllowEdits = True
Me.aTable_subform.Form.AllowDeletions = False
End Select
End Sub
进一步说明重新评论
选项 2
您可以在主表单打开时打开一个弹出表单。在本例中,它将在主窗体之前可见。
主窗体上的代码:
Private Sub Form_Close()
DoCmd.Close acForm, "popupform"
End Sub
Private Sub Form_Load()
DoCmd.OpenForm "popupform", , , , , acDialog
End Sub
Private Sub PickOne_BeforeUpdate(Cancel As Integer)
Select Case Me.PickOne
Case 1
If MsgBox("You chose this. Continue?", vbYesNo) = vbYes Then
Forms!mainform.AllowAdditions = True
Forms!mainform.AllowEdits = True
Forms!mainform.Form.AllowDeletions = True
''Setting the visibility leaves the form
''available but it is no longer a dialog form
''but you must remember to close it elsewhere
''If the form is not needed, just close it here
Me.Visible = False
Else
Cancel = True
End If
Case 2
''Whatever
End Select
End Sub
选项 3
每个控件都有一个供设计人员使用的标记属性,例如,您可以将“Admin”添加到所有需要锁定的控件。哟必须使用加载事件,或稍后的事件。
Private Sub Form_Load()
For Each ctrl In Me.Controls
''For example:
If ctrl.Tag = "Admin" And TheOption <> "Admin" Then
ctrl.Locked = True
End If
Next
End Sub
您可以轻松拥有多个标签,一个用于管理员用户或 OptionX,另一个用于其他用户或 OptionY。
于 2013-03-26T17:17:00.777 回答
1
您可以使用 VBA 过程循环遍历表单的 Controls 集合并将每个控件的.Locked
属性设置为True
. 检查每个控件的.ControlType
属性,并忽略标签和命令按钮等控件。IOW,.Locked
只为有意义的那些类型的控件设置。
于 2013-03-26T16:52:01.107 回答