Full Version: Dcount and referencing current record
UtterAccess Discussion Forums > Microsoft® Access > Access Tables + Relationships
asn3311
I am having problems in using dcount to count records with the same value as the current record in my form. I have attached my database. Here is what I have tried so far (and the results):

=DCount("[NumCode]","Req_Rev_PP","[NumCode] ='002'")
correctly counts #in Req_Rev_PP that have NumCode=”002”

=DCount("[SecCode]","[Req_Rev_PP]","[SecCode] ='CP'")
correctly counts #in Req_Rev_PP that have SecCode=”CP”


=DCount("[NumCode]","Req_Rev_PP","[NumCode]='“&[Forms]![Pol_Proc_Info]![NumCode] & ” '")
does not correctly count #in Req_Rev_PP that has same SecCode as current record in Pol_Proc_Info (returns 0)

Ultimately I want to count records in Req_Rev_PP that have the same NumCode AND the same SecCode as current record in Pol_Proc_Info

--Annamarie
BenPurser
Try this, assuming both numcode and seccode are text fields:

=DCount("[NumCode]","Req_Rev_PP","[NumCode]='" & me.[numcode] & "' and [SecCode]='" & me.[secCode] & "'")

HTH
Ben
asn3311
Using your code I keep get this: #Name?

I tried using similar code where I only use either NumCode or SecCode but then I get a count of 0 for every record.

Both NumCode and SecCode are text fields. However, in the "policies" table SecCode is a combo box but is just a text field in "requests". Does this matter? Should I make them combo boxes in both tables? NumCode is just a regular text field in both tables (and I can't get this to work even if I'm just trying to match on NumCode).

I know this is not supposed to be so difficult and figure I've just set something up wrong.

Thanks!
Annamarie
BenPurser
Try this..I have a message box that pops up in the On Current event that counts the recs for you. I changed a bit of the data in the table where you're counting recs just to make sure it counts correctly.

HTH
Ben
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.