Access VBA: Resetting a Date on a Form

Asked by At

I'm trying to create a button with VBA code (on click) to empty a form in order for a new entry to be started, or an entry to be restarted. The below code works...

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

for everything besides a Date field that I have. I can't figure out how to reset the date to either 00:00:00:00 or just an empty box. I'd prefer an empty box, but am having trouble finding any information on how to do it. Thanks!

Updated Code:

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 Answers

0
Gustav On Best Solutions

That is:

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

But, as noted, there is no "Date" control, thus you can reduce to:

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