Dcount on report's text box

venu_resoju

Registered User.
Local time
Tomorrow, 02:25
Joined
Dec 29, 2010
Messages
130
Hai Friends..

I am trying to count a "Sex" field in a query named "PayrollQuery" by using DCount function, but it is not working and saying syntax error. the code is mentioned below..
Code:
=DCount("sex", "PayrollQuery", "Sex='Male'" AND' Payperiod between #" & ([Forms]![LCR]![cbomonth] & "-" & [Forms]![LCR]![cboyear]) & "# AND #" & ([Forms]![lcr]![txtdate2]) &  "#")

in the above code...
([Forms]![LCR]![cbomonth] & "-" & [Forms]![LCR]![cboyear]) is start date and here cbomonth and cboyear are not date fields.

[Forms]![LCR]![cboyear] is end date and it is a date filed.

please anybody help me to correct my code..

thanks in advance.
 
If Payperiod is a true date/Time field then use DateSerial() function to make a startdate

Code:
=DCount("[COLOR="red"]*[/COLOR]", "PayrollQuery", "Sex='Male' AND Payperiod between #" & [COLOR="red"]DateSerial([Forms]![LCR]![cboyear],[Forms]![LCR]![cbomonth],1)[/COLOR] & "# AND #" & ([Forms]![lcr]![txtdate2]) &  "#")

changes marked in red

JR
 
thanks for your reply JANR

I have put this code but am getting #Error
I have attached my DB here, please find the attachment and find my problem.

Thanking you sir,
 

Attachments

Users who are viewing this thread

Back
Top Bottom