vba 使用 SQL 将今天的日期插入 Access 表中
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20679633/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Insert todays date into Access table using SQL
提问by user1894555
Im trying to use an SQL statement to insert the current date into an access table.
我试图使用 SQL 语句将当前日期插入到访问表中。
Ive got
我有
DoCmd.RunSQL "INSERT INTO tblImportedData (dtmReportDate) VALUES Now();"
This isnt working. Anybody know what im doing wrong?
这不起作用。有人知道我做错了什么吗?
回答by Amber
You need to put Now()
between brackets like this:
你需要Now()
像这样放在括号之间:
INSERT INTO tblImportedData (dtmReportDate) VALUES (NOW())
回答by Dan
You need to put parenthesis around your list of values, even though there's only one column you're inserting into:
您需要在值列表周围加上括号,即使您只插入一列:
DoCmd.RunSQL "INSERT INTO tblImportedData (dtmReportDate) VALUES (Now());"
回答by dylanT
For completeness, and because I came here looking for date, not datetime, if you need to enter the current date (as opposed to date and time) you can use:
为了完整起见,并且因为我来这里是为了寻找日期,而不是日期时间,如果您需要输入当前日期(而不是日期和时间),您可以使用:
DoCmd.RunSQL "INSERT INTO tblImportedData (dtmReportDate) VALUES (Date())"