Programmatically Apply a Filter to a Subform

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?
 
S

Stefan Hoffmann

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 <--
 
G

Guest

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
 
S

Stefan Hoffmann

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 <--
 
B

Benoit Lamarche

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top