简体   繁体   English

Access 2013 vba - 清除表单控件,绕过计算控件

[英]Access 2013 vba - clear a form's controls, bypassing calculated controls

I would like to clear all the controls in an Access 2013 form.我想清除 Access 2013 表单中的所有控件。 I found the following script on this site by Johan Godfried and it works very well.我在 Johan Godfried 的网站上找到了以下脚本,它运行良好。

Private Sub resetForm()

Dim ctl As Control

For Each ctl In Me.Controls
    Select Case TypeName(ctl)
        Case "TextBox"
            ctl.value = ""
        Case "CheckBox", "ToggleButton"
            ctl.value = False
        Case "OptionGroup"
            ctl = Null
        Case "OptionButton"
            ' Do not reset an optionbutton if it is part of an OptionGroup
            If TypeName(ctl.Parent) <> "OptionGroup" Then ctl.value = False
        Case "ComboBox", "ListBox"
            ctl.RowSource = vbNullString
    End Select
    Next ctl
 End Sub

Except that when the iteration selects a calculated control I receive the following error: You can't assign a value to this object .除了当迭代选择计算控件时,我收到以下错误: You can't assign a value to this object

Is there a property that can be used to by-pass calculated controls?是否有可用于绕过计算控件的属性?

try Me.myControl.controlsource="" to unbound that control尝试Me.myControl.controlsource=""解除该控件的绑定

and then call resetForm()然后调用resetForm()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM