Is it possible to create a form that displays all records in a query but allows the user(viewer) of the form to filter the records based on one or more colomns in the view?
Is it possible to create a form that displays all records in a query but allows the user(viewer) of the form to filter the records based on one or more colomns in the view?
Yes, either modify the forms recordsource, or better yet, set the form's "FilterOn" property to Yes, and the form's "Filter" property to your filter criteria.
Good morning,
thanks for sharing. I am not sure I am clear on how your 2nd solution would work. What do I put in the "Filter" property. the field name that I want to filter on? I tried this and nothing happen when I ran the report.
The filter property is set to exactly the same thing that would be in the WHERE clause of a SQL query but without the word "WHERE", e.g
Also, setCode:
Me.Filter ="YourFilterFieldName=" & integervalue ' for an integer value
or
Me.Filter ="YourFilterFieldName='" & textstring & "'" ' for a text string
or
Me.Filter ="YourFilterFieldName=#" & adate "#" ' for a date
or
Me.Filter = "YourFilterFieldName=" & me.YourfilterfieldFormControlName ' for a referenced value
Code:
Me.FilterOn = true
If I want to filter on last name and the field for last name is LName would the code from above look like the following:
Me.Filter ="LName='" & textstring & "'" ' for a text string
sorry, I know every little about VBA code. I am sure you coloar coding of the code has meaning but I am not familiar.
The color coding is added by this forum.
Your Filter property is correct.
Don't forget to set FilterOn=True
I need help with one more thing then. Where do I add "Me.FilterOn=True"
Immediately before the "Me.Filter=..." line.
Maybe I am confused as to where this previous code goes. I was putting it in the the field called "Filter" on the DATA tab of the form properties. Is that were it goes or does it go somewhere else?
If you adding the filter in the property window, use
For the property "Filter"
for the property FilterOnCode:
"LName=" & integervalue ' for an integer value
or
"LName='" & textstring & "'" ' for a text string
or
"LName=#" & adate "#" ' for a date
or
"LName=" & me.YourfilterfieldFormControlName ' for a referenced value
I though that you were setting same following some event. Hardcoding the Filter and Filtefor properties works only for the specified value filter value, unless it's a referenced value.Code:
Yes
no, I do not want to hard code a filter value. I was hoping the form could be interactive and allow the user to type a value or select a value to filter on.
anther words, when the user opens the form they can apply the filter themselves in some way.
Use
FilterOn property
Code:
Yes
Filter property
for a referencing a control on your form, probably a combo boxCode:
"LName=" & me.YourfilterfieldFormControlName
Any time me.YourfilterfieldFormControlName changes, the form will display different data.
let me try that