Solved

Filter a form between two dates

Posted on 2004-04-19
8
980 Views
Last Modified: 2008-02-01
Hi,

I have a tabular form,  at the top I want to put two form fields to filter the form by.

The fields will be dtStart and dtEnd.  How can I use the filter commands with between.

I mean by using me.filter= and me.filteron=True

Thanks a lot
0
Comment
Question by:hhammash
8 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 10862351
On your query add the where clause

Where (TableA.Date) Between Me.dtStart And Me.dtEnd;
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 10862410
What is the Record Source of your form?
Is this the same form you will be using to display the result or something else?
0
 
LVL 14

Author Comment

by:hhammash
ID: 10862497
Hi,

The record source of the form is a query,  and yes I'll be using the same form to display the results.

This is the filter code I am using on the form in the OnClick event of a combo box:

Me.Filter = "[InvoiceNo]='" & Me.cboInvoice & "'"
Me.FilterOn = True

When I select the cboInvoice I get the resutls on the same form.

I just want to add  two textboxes to filter the records between two dates.  Using the same colde  Me.filter= ?????
Me.filterOn=True.

I tried to use the between or => and <= but nothing worked.

Thanks
0
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 

Expert Comment

by:luckyrebel
ID: 10862581
try

Between [Me.dtStart] and [Me.dtEnd]

Works pretty well for me.  
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 10862643
In that case you need to set your filter this way;

Private Sub ApplyFilter()
Dim strFilter As String
strFilter=""

    If Me.cboInvoice<>"" And Not IsNull(Me.cboInvoice) Then
        If strFilter = "" Then
        strFilter = "[InvoiceNo]=" & Chr(34) & Me.cboInvoice & Chr(34) & " And"
        Else
        strFilter = strFilter & "[InvoiceNo]=" & Chr(34) & Me.cboInvoice & Chr(34) & " And"
        End If
    End If

    If Me.dtStart <>"" And Not IsNull(Me.dtStart) And Me.dtEnd <>"" And Not IsNull(Me.dtEnd) Then
        If strFilter = "" Then
        strFilter= " [DateField]= Between " & Me.dtStart & "  And " & Me.dtEnd & " And"
        Else
        strFilter= strFilter & " [DateField]= Between " & Me.dtStart & "  And " & Me.dtEnd & " And"
       End IF
    End If

    If strFilter <> "" Then
    strFilter = Left(strFilter, Len(strFilter) - 5)
    End If

    Me.Filter = strFilter
    Me.FilterOn = True
    Me.Refresh
   
End Sub

'Instead of placing the codes on Click event of the combo box
'Place the codes on the AfterUpdate  Event

Private Sub cboInvoice_AfterUpdate()
ApplyFilter
End Sub


0
 
LVL 7

Expert Comment

by:ala_frosty
ID: 10863403
You wrote:
"I tried to use the between or => and <= but nothing worked."

Use these again, but you need to delimit the dates with '#' rather than the single apostrophe you used with the character data.
0
 
LVL 7

Accepted Solution

by:
ala_frosty earned 500 total points
ID: 10863442
So ...

Me.Filter = "[DateField] BETWEEN #" & Me.dtStart & "# AND #" & Me.dtEnd & "#"
Me.FilterOn = True

HTH
0
 
LVL 7

Expert Comment

by:ala_frosty
ID: 10863465
You may run into some trouble with the time inclusion in the dates including and excluding some values that you think should be included or excluded, but this should get you on the right track.
0

Featured Post

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question