Link to home
Start Free TrialLog in
Avatar of WS
WSFlag for United Arab Emirates

asked on

MS Access - Filter subform based on date selected in main/parent form

Hello,

I have a form that have multiple listbox with multiple selection and they are filtering subform. Now i want to have filter subform based on date selected in texbox in mainform. VBA code can be use to filter. Also attach is the DB in which frmListBox is the one that have date textbox . When date is selected from that it should filter subform field Timestamp.

Any help would be appreciated.

Thank you.
Wsm93.accdb
Avatar of Gustav Brock
Gustav Brock
Flag of Denmark image

You can just expand your filter function to include:

    If Not IsNull(Me!Timestamp.Value) Then
        strFilter = strFilter & " And Timestamp = #" & Format(Me!Timestamp.Value, "yyyy\/mm\/dd") & "#"
    End If

Open in new window

See attached demo.

/gustav
Wsm93.accdb
Avatar of WS

ASKER

Wow Gustav , that's amazing, but i came across one more thing if you could sort that related to this. In my operational database i have time also with date,so could you please help me in filtering record as between two dates. In the attach DB i have make changes. If instead of finding the exact date how it could be change as From Date and To Date considering that there are time also with date (We don't need to filter date it's just between two dates and record that in any time between them should filter out).

Thank you again,
Wsm93--1-.accdb
You could cut the time part of the stored dates with Fix:

    If Not IsNull(Me!Timestamp.Value) Then
        strFilter = strFilter & " And Fix(Timestamp) = #" & Format(Me!Timestamp.Value, "yyyy\/mm\/dd") & "#"
    End If

Open in new window

/gustav
Avatar of WS

ASKER

Gustav it's working for time but how to filter between two dates? Example i want to find all records that between 1 August 2017 and 20 August 2017, how that will work?
Wsm93--1-.accdb
SOLUTION
Avatar of Gustav Brock
Gustav Brock
Flag of Denmark image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of WS

ASKER

It's not working. It's giving error. Have a look at it.
Wsm93--1-.accdb
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of WS

ASKER

Thank you Gustav. (y)
You are welcome!

/gustav