Filtering a Form (1 Viewer)

mjfrelich

New member
Local time
Today, 00:21
Joined
Jul 24, 2012
Messages
4
Good Afternoon,
Trying to filter my form from a combo box selection. My database contains one main table for all the data and the client would like to be able to filter the form to show only certain records; they ultimately want to be able to filter by County, Facility, or both.

For the filters, I have a combo box that is used to retrieve the data from the user to use as the filter value. Below is the code that I am using to apply the filter:

Private Sub ApplyFormFilter_Click()

Dim sCFiltVal As String

sCFiltVal = "County = " & Me.CountyFilter

Me.Fitler = sCFiltVal
Me.FitlerOn = True

End Sub

When the code runs, I get a text box asking me to "Enter Parameter Value" and the text box displays the "County" Value that I applied via the code (see attached image). If I enter the value for the county, it works. But why am I getting this text box asking for the filter value again?
 

Attachments

  • FormFilter_Dialog.bmp
    68.3 KB · Views: 89

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 21:21
Joined
Aug 30, 2003
Messages
36,140
Your field is text. Try:

sCFiltVal = "County = " & Chr(34) & Me.CountyFilter & Chr(34)
 

mjfrelich

New member
Local time
Today, 00:21
Joined
Jul 24, 2012
Messages
4
Thank you! That was the problem. I am newer at Access and VBA and only have a sporadic intervals at work where I actually need to use these two great programs. I appreciate the help and look forward to learning more...I am sure I will be posting again soon!
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 21:21
Joined
Aug 30, 2003
Messages
36,140
Happy to help! Generally speaking, text values need to be surrounded by quotes, date values by #, nothing around numbers. That's all based on the data type of the field.
 

mjfrelich

New member
Local time
Today, 00:21
Joined
Jul 24, 2012
Messages
4
Private Sub ClearFormFilter_Click()

Dim sCFiltVal As String

sCFiltVal = ""

Me.Fitler = sCFiltVal
Me.FitlerOn = False

End Sub

When I use the above code, the filter is removed and I see all records on my form but when I view the "Filter" property of my form I still see the sCFiltVal that was placed there previously by my ApplyFormFilter_Click code. Any idea why my code is not removing the text from the "Filter" property value?
 

Users who are viewing this thread

Top Bottom