Programmatically Apply a Filter to a Subform

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have:
A form that has two combo boxes (cboCity and cboCountry) and a command
button (cmdFilter). The subform contains contact information.

I want:
When a user clicks the "Filter" button on the form, the subform is filtered
by the values in the city and country combo boxes.

Any suggestions?
 
hi Daniel,
I have:
A form that has two combo boxes (cboCity and cboCountry) and a command
button (cmdFilter). The subform contains contact information.

I want:
When a user clicks the "Filter" button on the form, the subform is filtered
by the values in the city and country combo boxes.

Private Sub cmdFilter_Click()

SubFormCtlName.Form.Filter = "idCity=" & cboCity.Value & " AND " _
"idCountry=" & cboCountry.Value
SubFormCtlName.Form.FilterOn = True

End Sub


mfG
--> stefan <--
 
It worked, with a little tweaking on the quotation marks. Thank you!

SubFormCtlName.Form.Filter = "idCity='" & cboCity.Value & "' AND
idCountry='" & cboCountry.Value & "'"

SubFormCtlName.Form.FilterOn = True
 
hi Daniel,
It worked, with a little tweaking on the quotation marks. Thank you!
SubFormCtlName.Form.Filter = "idCity='" & cboCity.Value & "' AND
idCountry='" & cboCountry.Value & "'"
Using the ' indicates that you are using strings as ident values.

Then you should reconsider your naming conventions. A field named
idSomething or ID is normally a surrogat key of type integer.


mfG
--> stefan <--
 
I have the same situation, except when I click on the button I get an Object
Required message. The debugger highlights the second line. The field "Engine"
is a text field. Am I missing something on the quotes? Do I have to create a
variable?

Here's my code:

*-------------------

Private Sub Command_SetFilter_Click()

tbl_engineruntimesSubform.Form.Filter = "Engine =" &
Combo_Engine_Filter2.Value

tbl_engineruntimesSubform.Form.FilterOn = True

End Sub

*-------------------


"tbl_engineruntimesSubform" is the name of the subform (obviously)
"Combo_Engine_Filter2" is the name of the combo box
 
Back
Top