访问VBA:在表单上重置日期

时间:2019-04-30 15:25:20

标签: vba date ms-access controls

我正在尝试创建一个带有VBA代码(单击时)的按钮,以清空表单,以便启动新条目或重新启动条目。下面的代码有效...

Public Sub clearForms()
Dim frm As Form
Set frm = Forms!Person_Name

Dim ctl As Control

For Each ctl In frm.Controls
    With ctl
        Select Case .ControlType
            Case acTextBox
                .Value = " "
            Case acCheckBox
                .Value = False
            Case acComboBox
                .SetFocus
                .SelText = " "
            Case acListBox
                .Value = Null
            Case acDate

        End Select
    End With
Next ctl

MsgBox "forms cleared"
End Sub

除我拥有的Date字段外的所有内容。我不知道如何将日期重置为00:00:00:00或只是一个空框。我希望使用一个空盒子,但是找不到有关如何做的任何信息。谢谢!

更新代码:

Public Sub clearForms()
Dim frm As Form
Set frm = Forms!Person_Name

Dim ctl As Control

For Each ctl In frm.Controls
    With ctl
        Select Case .ControlType
            Case acTextBox
                .Value = " "
            Case acCheckBox
                .Value = False
            Case acComboBox
                .SetFocus
                .SelText = " "
            Case acListBox
                .Value = Null
            Case acDate
                .Value = #12:00:00 AM#
        End Select
    End With
Next ctl

MsgBox "forms cleared"
End Sub

1 个答案:

答案 0 :(得分:0)

也就是说:

Case acDate
    .Value = #00:00:00#

但是,如上所述,没有“日期”控件,因此您可以简化为:

For Each ctl In frm.Controls
    With ctl
        Select Case .ControlType
            Case acTextBox, acComboBox, acListBox
                .Value = Null
            Case acCheckBox
                .Value = False
        End Select
    End With
Next ctl