Filter form based on user input

Hi Experts,

I am working on a physical inventory database that uses a single table to hold all items to be inventoried.  Each item is unique based on the inventory period and the location where it is physically counted.  To enter the physical counts, each department has its own form filtered by department and sorted by location to match the counting sheets from the physical inventory.  I'm stuck on how to filter the form with user input based solely on the inventory period date.  I've researched how to pass the content from a combobox to form's filter property but I just don't understand how the code works.  If that isn't the correct approach, how do I structure a query that would use a date from another table.  I've attached a portion of the db for illustration.  Thank you, any help would be greatly appreciated!
InventoryDateFiltering.accdb
Skip SleeperIT ManagerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Gustav BrockCIOCommented:
You can use code like this with two unbound textboxes:

Private Sub FromDate_AfterUpdate()

    FilterDates

End Sub

Private Sub FilterDates()

    Dim Filter  As String
    
    Filter = ""
    
    ' Build filter.
    If Not IsNull(Me!FromDate.Value) Then
        Filter = "InventoryPeriodDate >= #" & Format(Me!FromDate.Value, "yyyy\/mm\/dd") & "#"
    End If
    If Not IsNull(Me!ToDate.Value) Then
        If Filter <> "" Then
            Filter = Filter & " And "
        End If
        Filter = Filter & "InventoryPeriodDate <= #" & Format(Me!ToDate.Value, "yyyy\/mm\/dd") & "#"
    End If
    
    ' Apply filter.
    Me.Filter = Filter
    Me.FilterOn = (Filter <> "")
    
    ' Debug.Print Me.FilterOn, Me.Filter

End Sub

Private Sub ToDate_AfterUpdate()

    FilterDates
    
End Sub

Open in new window

See the attached demo, please.
InventoryDateFiltering.accdb
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Skip SleeperIT ManagerAuthor Commented:
Hi Gustav,

I can't believe you did that so fast!  I'm going to get there someday...

If you don't mind, what are the procedures at the start and end of your code?

Thank you!
0
Gustav BrockCIOCommented:
Those are the events raised  when a date has been changed (or deleted).

They both call the same subfunction to set (or remove) the filter.
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Skip SleeperIT ManagerAuthor Commented:
Why isn't there a "command" preceding the FILTERDATES in the events code?
Thanks!
0
Gustav BrockCIOCommented:
That is not need. VBA looks up the name, finds it as a subfunction, and runs it.

If you prefer, you can write, using the old syntax:

    Call FilterDates()

Open in new window

0
Skip SleeperIT ManagerAuthor Commented:
Just curious-thanks for the info and the help!
0
Skip SleeperIT ManagerAuthor Commented:
Great help!
0
Gustav BrockCIOCommented:
You are welcome.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Databases

From novice to tech pro — start learning today.