I am trying to count records between two dates specified in a form. When I run the code I get the total of records form the beginning of the file to the last date criteria.
When I run the code without variables but simply substituting the dates directly in the code I get the right answer. Clearly my criteria expression is wrong but I have tried a number of ways to get it and cannot get right answer.
This is waht I have done:
1) I declare variables to hold the dates & one to hold the count answer
2) Set the variables to the values in the form
3) Do calculation
Dim FirstDate As Date
Dim SecondDate As Date
Dim CompsDates As Long
FirstDate = Me.txtDate1
SecondDate = Me.txtDate2
CompsDates = DCount("*", "tbl_Compliments_Log", "[Date_Raised] Between #" & FirstDate & "# AND #" & SecondDate & "#")
This code works:
CompsDates = DCount("*", "tbl_Compliments_Log", "[Date_Raised]>= DateValue('1/08/2003') AND [Date_Raised]<= DateValue('31/08/2003')")
Any suggestions
Thanks
When I run the code without variables but simply substituting the dates directly in the code I get the right answer. Clearly my criteria expression is wrong but I have tried a number of ways to get it and cannot get right answer.
This is waht I have done:
1) I declare variables to hold the dates & one to hold the count answer
2) Set the variables to the values in the form
3) Do calculation
Dim FirstDate As Date
Dim SecondDate As Date
Dim CompsDates As Long
FirstDate = Me.txtDate1
SecondDate = Me.txtDate2
CompsDates = DCount("*", "tbl_Compliments_Log", "[Date_Raised] Between #" & FirstDate & "# AND #" & SecondDate & "#")
This code works:
CompsDates = DCount("*", "tbl_Compliments_Log", "[Date_Raised]>= DateValue('1/08/2003') AND [Date_Raised]<= DateValue('31/08/2003')")
Any suggestions
Thanks