创建直观表单的实用技巧与方法
1. 根据用户角色设置只读字段
在某些情况下,我们需要根据当前用户的角色来设置表单中字段的只读属性。以 frmDemoTagReadOnly 表单为例,它使用组合框来模拟确定用户角色的过程,并在表单的 Open 事件中使用以下代码根据所选角色设置只读字段:
Private Sub Form_Open(Cancel As Integer)
'Initiate the user's role in memory based on the combobox value
TempVars.Add "UserRole", Me.cboUserRole.Value
'Set read-only fields based on current user's role
Dim ctl As Control
Dim blnAdmin As Boolean
'Check user's role
If Nz(TempVars("UserRole"), "User") = "Admin" Then
blnAdmin = True
Else
blnAdmin = False
End If
For Each ctl In Me.Controls
If ctl.Tag = "readonly" Then
Select Case ctl.ControlType
Case acTextBox
超级会员免费看
订阅专栏 解锁全文
1139

被折叠的 条评论
为什么被折叠?



