vba Docmd.openreport Where 子句语法
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21963004/
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
Docmd.openreport Where Clause syntax
提问by user3342193
I am trying to save individual records in a report to PDF files. using Access 2010
. I got this to work, but I need to put a start date and end date in, and I can't seem to figure out the syntax. Here is what I have so far:
我正在尝试将报告中的单个记录保存为 PDF 文件。使用Access 2010
. 我让它工作了,但我需要输入开始日期和结束日期,而且我似乎无法弄清楚语法。这是我到目前为止所拥有的:
DoCmd.OpenReport "Rpt Form Responses", acViewReport, , "[Facility Number]=" & temp & _ And [Service Date] Between & begindate And enddate;
The top line works fine but when I add the second I can't get it to work. I have tried all the qualifiers'
, "
, and #
and many different variations of syntax with no luck.
第一行工作正常,但是当我添加第二行时,我无法让它工作。我已经尝试了所有限定符'
、"
和#
以及许多不同的语法变体,但都没有成功。
begindate and enddate are strings that I capture from an input box. Should I change these to a date? I have done a lot of reading on here and based on suggestions I thought about putting a text box on the form for begin and end but I think I would rather do the inputbox.
begindate 和 enddate 是我从输入框中捕获的字符串。我应该将这些更改为日期吗?我在这里做了很多阅读,根据建议,我想在开始和结束的表单上放置一个文本框,但我想我宁愿做输入框。
回答by Wayne G. Dunn
Are you sure the syntax you posted above is accurate, because it is not correct.
你确定你上面发布的语法是准确的,因为它不正确。
- I am assuming 'temp' is numeric, else you need to enclose in single-quotes;
- Tthe continuation line is missing the leading " followed by a space;
- Missing quotes, spaces around your BETWEEN and AND
- 我假设 'temp' 是数字,否则你需要用单引号括起来;
- 续行缺少前导 " 后跟一个空格;
- BETWEEN 和 AND 周围缺少引号、空格
You can get away with strings for the dates as long as you did something like:
只要您执行以下操作,您就可以摆脱日期的字符串:
begindate = #1/1/2005#
enddate = #1/1/2012#
Here is what I believe your syntax should look like (I tested and it works):
这是我认为您的语法应该是什么样子的(我测试过并且可以正常工作):
DoCmd.OpenReport "Rpt Form Responses", acViewReport, , "[Facility Number]=" & temp & _
" And [Service Date] Between #" & begindate & "# And #" & enddate & "#"