【发布时间】:2019-04-30 15:25:20
【问题描述】:
我正在尝试创建一个带有 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
【问题讨论】:
-
为什么不应用 Null 值到日期?
-
@VanNg
acDate不起作用。无论.Value我尝试给出什么,它都会给我一个未定义的变量错误 -
.Value = Null 给出什么类型的错误?
-
@VanNg 变量未在“acDate”上定义
-
是的。因为没有这种类型 - 请参阅documentation.help/MS-Access-Visual-Basic/acproControlType.htm
标签: vba date ms-access controls