Hello all,
me again! Got a very strange error today when trying to filter on a form that maybe someone has seen before.
I have a form that displays a list of outstanding work items for a user. They have the ability to filter these items based on, among other things, the date that they came in.
So I have 2 unbound text boxes for the date range itself, both set to Short Date format (UK format - dd/mm/yyyy). The date field on the table and form is the same format.
So I have the following code to implement the filter, and if I type in dates like, for example, 15th June 2009 to 26th June 2009 (in the Short Date format) it all works ok. However if I type in a single digit day (i.e. anything from the 01st to the 09th of a month) it converts the date into US format for the actual filtering. I have a msgbox set up to check the dates as I filter and it seems fine there, but the filter itself is incorrect.
Anyone got any ideas????? It's really bugging me now!
Thanks,
John.
me again! Got a very strange error today when trying to filter on a form that maybe someone has seen before.
I have a form that displays a list of outstanding work items for a user. They have the ability to filter these items based on, among other things, the date that they came in.
So I have 2 unbound text boxes for the date range itself, both set to Short Date format (UK format - dd/mm/yyyy). The date field on the table and form is the same format.
So I have the following code to implement the filter, and if I type in dates like, for example, 15th June 2009 to 26th June 2009 (in the Short Date format) it all works ok. However if I type in a single digit day (i.e. anything from the 01st to the 09th of a month) it converts the date into US format for the actual filtering. I have a msgbox set up to check the dates as I filter and it seems fine there, but the filter itself is incorrect.
Code:
'Generate the SQL code for the filter
DateCriteria = "[Start Date]" & " >= #" & Format(Me.FromDateFilter, "dd/mm/yyyy") & "# AND " & "[Start Date]" & " <= #" & DateAdd("d", 1, Format(Me.ToDateFilter, "dd/mm/yyyy")) & "# AND Status <> 'Completed' AND [User Name] = '" & DLookup("[User Name]", "[Users]", "[User ID] = " & MyUserID) & "'"
'Count the results of the filter
FilterResults = DCount("[ID]", "[Tracker]", DateCriteria)
MsgBox DateCriteria, vbOKOnly, "Test"
'If there are results then apply the filter
If (FilterResults > 0) Then
'Set the global DateFilter variable to True - this will identify the date filter as being active in the event that
'other filters are also being used.
DateFilter = True
'Apply the criteria to the Form
Me.Filter = DateCriteria
Me.FilterOn = True
'If there are no results return an error
Else
MsgBox "There are no queries matching this date range criteria, please try again.", vbOKOnly, "No Queries Found"
End If
Anyone got any ideas????? It's really bugging me now!
Thanks,
John.