我如何才能清除大部分表单(但不是全部)的 MS Access 控件?

我如何才能清除大部分表单(但不是全部)的 MS Access 控件?

如何清除表单中大部分但不是全部的访问控制?我有一个控件 (Combo55),我想重置而不是清除,但不确定如何更改命令来执行此操作。以下是目前的代码:

Private Sub Command2061_Click()
'Clear

Const cstrPrompt As String = _
    "Are you sure you want to Clear this Form? Yes/No"
    If MsgBox(cstrPrompt, vbQuestion + vbYesNo) = vbYes Then
        Dim Ctl As Control
        On Error Resume Next
        For Each Ctl In Me.Controls
        Ctl.Value = Null
        Next Ctl

End If
End Sub

答案1

您可以测试每个控件的名称,然后执行您想要的操作

Private Sub Command2061_Click()
'Clear

Const cstrPrompt As String = _
    "Are you sure you want to Clear this Form? Yes/No"
    If MsgBox(cstrPrompt, vbQuestion + vbYesNo) = vbYes Then
        Dim Ctl As Control
        On Error Resume Next
        For Each Ctl In Me.Controls
        If Ctl.Name = "Combo55" Then
            'Your action here
            'Ctl.Value = "reset value"
        Else
            Ctl.Value = Null
        End if
        Next Ctl

End If
End Sub

相关内容