Problem using Dcount

J

Jess Wundring

I'm trying to use dcount to give me the count of a subset of records. It's
always returning a count of ALL the records in the table.

For example,

myCount = DCount("[caseid]", "tblCaseCharges", """[caseid] = '" & ID &
"'""")
MsgBox "myCount = " & myCount & " and " & """[caseid] = '" & ID & "'"""

displays this in the message box:

myCount = 7 and "[caseid] = '8"'

where 7 is actually the TOTAL number of records in the table. FWIW, caseid
is defined as a long int. I've been banging my head against the wall (and the
keyboard) on this. Please help if you can...

And Thanks
 
S

Stuart McCall

Jess Wundring said:
I'm trying to use dcount to give me the count of a subset of records. It's
always returning a count of ALL the records in the table.

For example,

myCount = DCount("[caseid]", "tblCaseCharges", """[caseid] = '" & ID &
"'""")
MsgBox "myCount = " & myCount & " and " & """[caseid] = '" & ID & "'"""

displays this in the message box:

myCount = 7 and "[caseid] = '8"'

where 7 is actually the TOTAL number of records in the table. FWIW, caseid
is defined as a long int. I've been banging my head against the wall (and
the
keyboard) on this. Please help if you can...

And Thanks

The problem is you're treating ID as a string. Removing the quotes should do
the trick:

myCount = DCount("[caseid]", "tblCaseCharges", "[caseid] = " & ID

MsgBox "myCount = " & myCount & " and " & "[caseid] = " & ID
 
J

Jess Wundring

Thanks, Stuart.

I thought I had tried that originally, but I must have had some other
problem because it does work. Whew! I'm glad I'm finally past this barrier.
 
S

Stuart McCall

Jess Wundring said:
I'm trying to use dcount to give me the count of a subset of records. It's
always returning a count of ALL the records in the table.

For example,

myCount = DCount("[caseid]", "tblCaseCharges", """[caseid] = '" & ID &
"'""")
MsgBox "myCount = " & myCount & " and " & """[caseid] = '" & ID & "'"""

displays this in the message box:

myCount = 7 and "[caseid] = '8"'

where 7 is actually the TOTAL number of records in the table. FWIW, caseid
is defined as a long int. I've been banging my head against the wall (and
the
keyboard) on this. Please help if you can...

And Thanks

The problem is you're treating ID as a string. Removing the quotes should do
the trick:

myCount = DCount("[caseid]", "tblCaseCharges", "[caseid] = " & ID

MsgBox "myCount = " & myCount & " and " & "[caseid] = " & ID
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Access Dcount (multiple criteria) 3
Access Dcount function in access 0
help with code 9
Problem with Criteria 3
Find Duplicates in one column and sum other column 4
Using the Access button wizard to link forms 6
Count query 2
DCount problem 12

Top