访问VBA:重置表单上的日期
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了访问VBA:重置表单上的日期相关的知识,希望对你有一定的参考价值。
我正在尝试创建一个带有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
答案
那是:
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
以上是关于访问VBA:重置表单上的日期的主要内容,如果未能解决你的问题,请参考以下文章