Disable all controls in 'details' section of a MS Access form

馋奶兔 提交于 2019-12-10 11:29:15

问题


I am looking for some command which will disable all controls present in the 'details' section of an MS Access Form. One way is to disable each and every control independently. I am looking for a control-independent way which would disable all the controls present in the details section of MS Access Form.

This feature might be useful, if the form is to be enabled based on some login credentials and the fields for entering credentials is placed in the header section of the form. So, as soon as user does login, all the controls in that form are enabled. Uplon logout, they shall be disabled.

I tried searching for it but it seems the same is not supported. Or no one had such a requirement before.

Please help me if anyone knows.


回答1:


A form has various properties that match this requirement: Allow Edits, Allow Additions and Allow Deletions. Allow Edits works for unbound controls, it even works on unbound forms.

If you have a requirement to disable certain controls, you can set the tab property for these controls to a string and then iterate through the form's control collection to disable those controls.

Dim frm As Form
Dim ctl As Control

Set frm = Forms!MyOpenForm

For Each ctl In frm.Controls

    If ctl.ControlType <> acLabel And ctl.ControlType <> acTabCtl Then
        If ctl.Tag = "AdminHide" Then
            If varWho = "Authorized" Then
                ctl.Visible = True
            Else
                ctl.Visible = False
            End If
        End If

    End If

Next



回答2:


You can disable all of the controls in the detail section directly without having to bother with tags:

Dim ctrl As Control
For Each ctrl In Detail.Controls
    If (TypeOf ctrl Is TextBox Or TypeOf ctrl Is ComboBox)
        ctrl.Enabled = False
    End If
Next

Similarly, you can get at the controls in the header and footer using FormHeader.Controls and FormFooter.Controls.

I usually prefer to use ctrl.Locked = True instead of ctrl.Enabled = False since users can still copy text from locked controls and use text filters on them, but that's up to you.



来源:https://stackoverflow.com/questions/13175021/disable-all-controls-in-details-section-of-a-ms-access-form

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!