0
votes

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.

The "Total_Sum" field data type is currency.

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'

The user opens the "Main Form" and pushes the "Reports" button. The "Reports" button opens the Report forms. There are 5 radio buttons. 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. 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..........

1
The [] brackets are being used when there is a space in the field name, or the field name is a keyword. Try without the brackets.Kostas K.

1 Answers

0
votes

If Total_Sum is a normal field of data type Currency, this will work:

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

Brackets ([])are used if table/field names are reserved words or contain strange characters.