Hello,
I am trying to limit the records in a recordset between two dates.
With a view to count the records and use that count later.
So, to test my code I created a continuous form with two unbound text
boxes to enter the dates and a button to apply the dates to the
recordsource.
Using the tips and hints from various sources, I figured the dates had
to be in American format. Thought I had cracked it, but testing has
proven that I get very anomalous results.
The table:
HolidayDate HolidayName
02-Jan-06 New Years Day
14-Apr-06 Good Friday
17-Apr-06 Easter Monday
01-May-06 Early May Bank Holiday
29-May-06 Spring Bank Holiday
28-Aug-06 Summer Bank Holiday
25-Dec-06 Christmas Day
26-Dec-06 Boxing Day
01-Jan-07 New Years Day
and the code:
__________________________________________________ ___________________________
Private Sub cmdDateLimiter_Click()
On Error GoTo Err_cmdDateLimiter_Click
Dim datStart As Date
Dim datEnd As Date
datStart = Format$(Me.txtStartDate, "mm\/dd\/yyyy")
datEnd = Format$(Me.txtEndDate, "mm\/dd\/yyyy")
Me.RecordSource = "Select * from tblHolidays where HolidayDate between
#" & datStart & "# and #" & datEnd & "#"
Me.Requery
Exit_cmdDateLimiter_Click:
Exit Sub
Err_cmdDateLimiter_Click:
MsgBox Err.Description
Resume Exit_cmdDateLimiter_Click
End Sub
__________________________________________________ ___________________________
When I enter "14-Apr-06" for txtStartDate and "01-May-06" for
txtEndDate
I get the last six records from "01-May-06 Early May Bank Holiday"
onwards. I would expect to get 3 records, "14-Apr-06" to "01-May-06"
inclusive.
Have I done something obviously wrong? or have I wandered down the
wrong track?
I appreciate any comments.
SEAN