简体   繁体   English

将 Dcount 与 Access VBA 结合使用会产生错误消息

[英]Using Dcount with Access VBA produces error message

I'm trying to create a number of reports in Access 2016. One report is a simple message box that will display the number of records in a specific table ("tbl_Data") WHERE the "Total_Sum" field is greater than $ 200.我正在尝试在 Access 2016 中创建多个报告。一个报告是一个简单的消息框,它将显示特定表(“tbl_Data”)中的记录数,其中“Total_Sum”字段大于 200 美元。

The "Total_Sum" field data type is currency. “Total_Sum”字段数据类型是货币。

The code I'm using to extract the number of records is as follows:我用来提取记录数的代码如下:

MyCnt = DCount("[Total_Sum]","tbl_Data", "[Total_Sum] > 200")

When the code executes, I'm getting the following error message:当代码执行时,我收到以下错误消息:

The expression you entered as a query parameter produced this error": 'Total_Sum'您作为查询参数输入的表达式产生了这个错误": 'Total_Sum'

The user opens the "Main Form" and pushes the "Reports" button.用户打开“主表单”并按下“报告”按钮。 The "Reports" button opens the Report forms. “报告”按钮打开报告表格。 There are 5 radio buttons.有 5 个单选按钮。 The user selects the appropriate radio button and it executes the code for each report.用户选择适当的单选按钮并为每个报告执行代码。 This part is working as it tries to execute the appropriate code.这部分在尝试执行适当的代码时正在工作。

I've done very little VBA programming in Access.我在 Access 中几乎没有做过 VBA 编程。 I've looked at a number of articles online and I believe I'm using code that should work but obviously something is wrong.我在网上看了很多文章,我相信我使用的代码应该可以工作,但显然有些问题。

Any help or suggestions would be greatly appreicated.任何帮助或建议将不胜感激。

Also, some examples I've seen include [] around field names and some don't.此外,我见过的一些示例在字段名称周围包含 [] ,而有些则没有。 I'd like to understand when [] are needed and when they aren't.我想了解什么时候需要 [] ,什么时候不需要。

Thanks again for your help..........再次感谢你的帮助..........

If Total_Sum is a normal field of data type Currency , this will work:如果Total_Sum是数据类型Currency的普通字段,这将起作用:

MyCnt = DCount("*", "[tbl_Data]", "[Total_Sum] > 200")

Brackets ( [] )are used if table/field names are reserved words or contain strange characters.如果表/字段名称是保留字或包含奇怪字符,则使用方括号 ( [] )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM