Question filter subform help

beefwellington

Registered User.
Local time
Today, 06:56
Joined
Jul 27, 2009
Messages
14
I have a form that when I filter it's subform to only shows results between certain dates like say 7/1/2009 and 8/24/2009, everything shows up fine. I have an entry in the subform that is dated 7/13/2009. When I change the filter to 7/2/2009 - 8/24/2009, it gets filtered out an doesn't show up. The 7/13/2009 entry doesn't show up if the July date is set to a number from 7/2-7/9. 7/10/2009-8/24/2009 works fine and it shows up. I've posted my code below and any help would be appreciated. It seems to be everything is correct code wise and I've even outputted the filter string to a msgbox to verify it was accepting the correct dates I was inputting and it was getting the correct dates.

Code:
Private Sub cmdFilter_Click()
    Dim strDateStart, strDateEnd As String
    Dim strFilter As String
    
    strDateStart = Format(Me.DateStart.Value, "mm/dd/yyyy")
    strDateEnd = Format(Me.DateEnd.Value, "mm/dd/yyyy")
    
    If Me.cboStatus.Value = "Down" Then
        strFilter = "[DateTimeLogged] BETWEEN #" & strDateStart & "# AND #" & strDateEnd & "# AND [StatusDown] = 'Down'"
    ElseIf Me.cboStatus.Value = "Up" Then
        strFilter = "[DateTimeLogged] BETWEEN #" & strDateStart & "# AND #" & strDateEnd & "# AND [StatusUp] = 'Up'"
    Else
        strFilter = "[DateTimeLogged] BETWEEN #" & strDateStart & "# AND #" & strDateEnd & "#"
    End If
    'MsgBox strFilter
    With Me.sfrmEquipment_History_List.Form
        .FilterOn = False
        .Filter = strFilter
        .FilterOn = True
    End With
End Sub

any help would be appreciated.
 
If your default system date format is mm/dd/yyyy then these lines are redundant:
Code:
strDateStart = Format(Me.DateStart.Value, "mm/dd/yyyy")
strDateEnd = Format(Me.DateEnd.Value, "mm/dd/yyyy")
So this suggests your default date format is not standard US. Access can get in a knot in trying to interpret non-US dates unless you are very careful.

As a UK user, I tend to use unambiguous formats like dd-mmm-yyyy to avoid this.
 
The textboxes "DateStart" and "DateEnd" have the date AND time as their value. DateStart's default value is "Now()-30" and DateEnd's default is "Now()". I used Format() so I could store just the date of "mm/dd/yyyy" (i.e. 8/26/2009 instead of 8/26/2009 9:01:16 AM) so that when it looks up the dates it filters BETWEEN #7/13/2009# AND #8/26/2009#

And yes, this the date by default is in standard US format.

Update 10:30AM (US EST time): I just tried the following...
1) Changing "DateStart" and "DateEnd" from Now() to Date(), but that did the same thing
2) Set the RecordSource for my subform WHERE to be between those dates, but that too did the same thing

The format is correct for both what the user can input and what is going into the filter (or query) is also the correct format. I'm still stumped since everything looks correct :/
 
Last edited:

Users who are viewing this thread

Back
Top Bottom