Multiple criteria filter help

E

Ed Lawrence

Hi! Ihave a form called "VendorSearch" that has comboboxes called
"vendorCounty", (which is linked to a zipcode table and displays county and
state) "vendorSpecialty", (which is linked to a table that has Vendor
Specialty names displayed Like "adjuster".) and a command button that when
clicked sets the filter for a form named "PropVendCounty" to filter the
records displayed. for instance: I select from the combobox VendorCounty the
value "adams county PA" and then from the VendorSpecialtycombo I select
"Adjuster" Then click on the comand button to open the form "propVendCounty:
to display the filtered records. My code only finds the county "Adams" But
does not give me adams county PA, it gives me all the adams counties in the
US. Also...How do I incorporate the criteria from the "VendorSpecialty" combo
? I am Includeing my decrepit code to embarrasss myself and for your
amusment. I really do need help on this one...many thanks in advance!

Private Sub CountyFind_Click()
On Error GoTo Err_CountyFind_Click

Dim stDocName As String
Dim stLinkCriteria As String
Dim stLinkCriteria2 As String
stDocName = "PropVendCounty"
stLinkCriteria = "[VendorCounty]=" & "'" & Me![VendorCounty] & "'"
stLinkCriteria2 = "[VendorCounty]=" & "'" & Me![VendorCounty] & "'"

DoCmd.OpenForm stDocName, , ,

Forms!PropVendCounty.Filter = "[VendorCounty] = '" & _
stLinkCriteria & " AND [VendorCountyState] = '" & stLinkCriteria2 & "'"
Forms!PropVendCounty.FilterOn = True

Exit_CountyFind_Click:
Exit Sub
Err_CountyFind_Click:
MsgBox Err.Description
Resume Exit_CountyFind_Click
End Sub
 
S

Svetlana

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "PropVendCounty"

stLinkCriteria="[VendorCounty]='" & Me![VendorCounty] & "'"
stLinkCriteria=stLinkCriteria & " AND [VendorSpecialty]='" &
Me![VendorSpecialty] & "'"

DoCmd.OpenForm stDocName, , , stLinkCriteria
 
E

Ed Lawrence

Thank you very much for the reply! It does work, but, the combo for county
also has a state , that state also must be included in the criteria. example:
when the dropdown is clicked it shows adams in the county colum and PA in the
stae colum. using your code it only filters the county and the state is
ignored. I really appreciate your help! thanks!
 
S

Svetlana

stLinkCriteria="[VendorCounty]='" & Me.[VendorCounty].Column(0) &"'"
stLinkCirteria=stLinkCriteria & " AND [VendorState]='" &
Me.[VendorCounty].Column(1) &"'"
stLinkCriteria=stLinkCriteria & " AND [VendorSpecialty]='" &
Me![VendorSpecialty] & "'"

Column(0) is for your first column in your combobox and Column(1) for
the second. You may need to change the numbers if they are not
corresponding with the right fields.
 
E

Ed Lawrence

Forgive me for my lack of ability...but thank you for your help! So now my
code will look like this since I need both columns:
stLinkCriteria="[VendorCounty]='" & Me.[VendorCounty].Column(0) &"'"
stLinkCirteria=stLinkCriteria & " AND [VendorState]='" &
Me.[VendorCounty].Column(0),(1) &"'"
stLinkCriteria=stLinkCriteria & " AND [VendorSpecialty]='" &
Me![VendorSpecialty] & "'"
 
M

Marshall Barton

Ed said:
Forgive me for my lack of ability...but thank you for your help! So now my
code will look like this since I need both columns:
stLinkCriteria="[VendorCounty]='" & Me.[VendorCounty].Column(0) &"'"
stLinkCirteria=stLinkCriteria & " AND [VendorState]='" &
Me.[VendorCounty].Column(0),(1) &"'"
stLinkCriteria=stLinkCriteria & " AND [VendorSpecialty]='" &
Me![VendorSpecialty] & "'"


There is an extraneous (0), in there. It should be:

Me.[VendorCounty].Column(1) &"'"
 

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