Solved Dcoount (1 Viewer)

sbaud2003

Member
Local time
Today, 14:43
Joined
Apr 5, 2020
Messages
178
I want to count the no of records in QPENSIONER_NEW TBL WHERE YR IS YEAR AND MN IN NAME OF MONTH
BUT I AM GETTING ERROR
Me.TXTCASE.value = DCount("REC_ID", "QPENSIONER_NEW", "YR = Forms!SERVICE_FORM!CYEAR " And MN = Forms!SERVICE_FORM!CMONTH)
 

bob fitz

AWF VIP
Local time
Today, 10:13
Joined
May 23, 2011
Messages
4,727
Perhaps:
Me.TXTCASE.value = DCount("REC_ID", "QPENSIONER_NEW", "YR = '" & Forms!SERVICE_FORM!CYEAR & "' And MN = '" & Forms!SERVICE_FORM!CMONTH & "'")
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 17:13
Joined
May 7, 2009
Messages
19,245
YR IS YEAR AND MN IN NAME OF MONTH
Code:
Me.TXTCASE.value = DCount("REC_ID", "QPENSIONER_NEW", "YR = " & Forms!SERVICE_FORM!CYEAR & " And MN = '" & Forms!SERVICE_FORM!CMONTH & "'")
 

ebs17

Well-known member
Local time
Today, 11:13
Joined
Feb 7, 2020
Messages
1,947
Code:
(1) DCount("REC_ID", ...  
 versus    
(2) DCount("*", ...
(1) counts contents of REC_ID, i.e. values that are not NULL
(2) counts records per se
So there can definitely be differences.

YR IS YEAR AND MN IN NAME OF MONTH
This is not the most clever way to store and process data. A date like the first of the month could be used much more flexibly; month and year and many other formats (calendar week, quarter) can be derived from a date.
 

sbaud2003

Member
Local time
Today, 14:43
Joined
Apr 5, 2020
Messages
178
Perhaps:
Me.TXTCASE.value = DCount("REC_ID", "QPENSIONER_NEW", "YR = '" & Forms!SERVICE_FORM!CYEAR & "' And MN = '" & Forms!SERVICE_FORM!CMONTH & "'")
No, Getting error as "Data Type Mismatch in criteria Expression" Both YR and MN is being extraxted from Date Field
 

sbaud2003

Member
Local time
Today, 14:43
Joined
Apr 5, 2020
Messages
178
Code:
Me.TXTCASE.value = DCount("REC_ID", "QPENSIONER_NEW", "YR = " & Forms!SERVICE_FORM!CYEAR & " And MN = '" & Forms!SERVICE_FORM!CMONTH & "'")
No, Getting error as "Data Type Mismatch in criteria Expression" Both YR and MN is being extraxted from Date Field
 

ebs17

Well-known member
Local time
Today, 11:13
Joined
Feb 7, 2020
Messages
1,947
Data Type Mismatch
As you can imagine, the two don't go together. So what data types do JR / CJEAR and MN/CMONTH have?
Don't be surprised, just check!

Both YR and MN is being extraxted from Date Field
You can usually also work directly with the date field. It is estimated that you are making your work more complicated and more prone to making errors by taking unnecessary intermediate steps.
 

Gasman

Enthusiastic Amateur
Local time
Today, 10:13
Joined
Sep 21, 2011
Messages
14,311
No, Getting error as "Data Type Mismatch in criteria Expression" Both YR and MN is being extraxted from Date Field
I tend to put the criteria into a string variable for domain functions if not a single simple criteria.
Then I can debug.print them to see if I have the syntax correct.
Then when correct, I can use that in the function.
Plus, if you cannot see the error, you can copy and paste here or eslewhere, so someone can point out the error.?

Strings need to be surrounded by single quotes ' unless it contains a single quote, then triple double quotes works, I think?

Date literals with # and in mm/dd/yyyy or yyyy-mm-dd format

Numbers do not need anything

Also for anything other than one item of criteria, I tend to put the the criteria into a string variable and then debug.print it, until correct then also use that in the code.

Added benefit is, if you still cannot see the error, you can copy and paste back here for someone else to spot it. :)
 

sbaud2003

Member
Local time
Today, 14:43
Joined
Apr 5, 2020
Messages
178
As you can imagine, the two don't go together. So what data types do JR / CJEAR and MN/CMONTH have?
Don't be surprised, just check!


You can usually also work directly with the date field. It is estimated that you are making your work more complicated and more prone to making errors by taking unnecessary intermediate steps.
Thanks a ton. I got the error, i was uning monthname function instead of month.
 

sbaud2003

Member
Local time
Today, 14:43
Joined
Apr 5, 2020
Messages
178
As you can imagine, the two don't go together. So what data types do JR / CJEAR and MN/CMONTH have?
Don't be surprised, just check!


You can usually also work directly with the date field. It is estimated that you are making your work more complicated and more prone to making errors by taking unnecessary intermediate steps.
Thanks a ton. I got the error, i was uning monthname function instead of month.
 

Users who are viewing this thread

Top Bottom