I've found many different solutions to a problem with dates that I'm having in this forum, but I just can't seem to get any of them to work for me.
Basically I've got a field called TransDate that's defined as Date Type Date/Time and Format Short Date. This is the date for transactions which are processed via the database. Then I've got a form with 2 fields where a user can enter a To Date and From Date - both fields are Format Short Date and have an Input Mask 00/00/0000;0;*. On the same form I have a command button - the code behind this button is where I'm trying to do a count of all transactions between the dates entered. However, I seem to be getting "silly" results being returned. Take the following records in my transaction table:
08/07/2004
08/07/2004
08/07/2004
08/07/2004
08/07/2004
10/07/2004
10/07/2004
This is a selection of 7 records in the table. Now if I enter the dates 01/07/2004 and 11/07/2004 it returns a count of 7 which is correct. But if I enter the dates 08/07/2004 and 09/07/2004 it returns a count of 0 when it should return a count of 5. I have tried various means and ways of counting the records, here are a few:
Unfortunately none of these seem to return the correct results. What am I doing wrong?
By the way, I'm in the UK as I know some of the replies in this forum regarding date questions are aimed at US users.
Basically I've got a field called TransDate that's defined as Date Type Date/Time and Format Short Date. This is the date for transactions which are processed via the database. Then I've got a form with 2 fields where a user can enter a To Date and From Date - both fields are Format Short Date and have an Input Mask 00/00/0000;0;*. On the same form I have a command button - the code behind this button is where I'm trying to do a count of all transactions between the dates entered. However, I seem to be getting "silly" results being returned. Take the following records in my transaction table:
08/07/2004
08/07/2004
08/07/2004
08/07/2004
08/07/2004
10/07/2004
10/07/2004
This is a selection of 7 records in the table. Now if I enter the dates 01/07/2004 and 11/07/2004 it returns a count of 7 which is correct. But if I enter the dates 08/07/2004 and 09/07/2004 it returns a count of 0 when it should return a count of 5. I have tried various means and ways of counting the records, here are a few:
Code:
intCount = DCount("TransNo", "tblTransP", "TransDate BETWEEN " & CDate(Me.txtFromDate) & " AND " & CDate(Me.txtToDate))
intCount = DCount("TransNo", "tblTransP", "TransDate BETWEEN " & Format(Me.txtFromDate, "dd/mm/yyyy") & " AND " & Format(Me.txtToDate, "dd/mm/yyyy"))
intCount = DCount("TransNo", "tblTransP", "TransDate BETWEEN #" & Me.txtFromDate & "# AND #" & Me.txtToDate & "#")
Unfortunately none of these seem to return the correct results. What am I doing wrong?
By the way, I'm in the UK as I know some of the replies in this forum regarding date questions are aimed at US users.