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

Posted

技术标签:

【中文标题】Access 2013 vba - 清除表单的控件,绕过计算的控件【英文标题】:Access 2013 vba - clear a form's controls, bypassing calculated controls 【发布时间】:2015-05-30 10:13:42 【问题描述】:

我想清除 Access 2013 表单中的所有控件。我在这个网站上找到了 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

除了当迭代选择计算控件时,我收到以下错误: 您不能为此对象赋值

是否有可用于绕过计算控件的属性?

【问题讨论】:

对于您希望清除的控件,您拥有什么作为控件源属性?这些目标控件的控件源是否为空? 【参考方案1】:

尝试Me.myControl.controlsource="" 解除该控件的绑定

然后拨打resetForm()

【讨论】:

以上是关于Access 2013 vba - 清除表单的控件,绕过计算的控件的主要内容,如果未能解决你的问题,请参考以下文章