DCount with string for fieldname

LixPri

New member
Local time
Today, 01:26
Joined
Jan 22, 2015
Messages
4
Access 2010 report. I am trying to use DCount but have a string for the fieldname and cannot figure out the correct syntax. This is what I have tried:

txtMiscYes1 = DCount("[" & str1 & "]", "tblTemp", "[" & str1 & "]" = '1')

I want to count any answer that has a 1 and skip a 2 or 3 answer.
Thank you for your help.
LIsa
 
Please review the Dcount syntax

It may also help readers if you would provide a little more detail in your description of the issue, and/or a sample of input and output you expect/would like.


I want to count any answer that has a 1 and skip a 2 or 3 answer.
Where does Answer appear???
 
I know how to use DCount. It's the string part and '" that is causing an error and your example for me to read shows no string examples so I can get the quotes correct. This DCount would appear in a text box on a report.
Detail of the issue, I am trying to count all the ones in a table column and not count a 2 ore three in the same column to get a total of correct answers. This is a questionaire summary report.
 
Please show the table structure and a few records. You may have to create a zip file to post because of the number of posts you have.

You may need a construct like this (purely guesswork since we don't know your table structure).

TotalAnswer_1 =TotalAnswer_1 + iif(Answerfield =1,1,0) or

SELECT * FROM YourTable Where Answerfield = 1

as recordsource for a report....

Need some context.
 
Try txtMiscYes1 = DCount(str1, "tblTemp", str1 & " = '1'") assuming 1 is a string or
txtMiscYes1 = DCount(str1, "tblTemp", str1 & " = 1") if 1 is a numeric field
 
Thank you Minty, very much. That worked perfectly and is what I was asking for.
 

Users who are viewing this thread

Back
Top Bottom