Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Filter via 2 combo boxes, 1 = field, 2 = Search criteria

Status
Not open for further replies.

sam225

Programmer
Nov 13, 2001
7
CA
I am trying to filter records based on 2 combo boxes. Using the following code, Access recognizes the Field to search as combo18.text (strField), yet it displays an input box and requests a parameter for the 2nd combo box (combo28.text or strField) and shows the item selected in the 2nd combo box as instructions for the parameter.

I am at a loss as to how to get the 2nd combo box to be accepted as the item to search for without the user having to manually enter a Parameter into an input box.

The following text is contained in a click event for a command button named 'cmdSearch'. The combo boxes are contained on a form which is based on a query.

If anyone can point out what I doing wrong or suggest another method to achieve the desired results I would appreciate it....

strField = Combo18.text
strCriteria = Combo28.Text
strCriteria = strCriteria & " and " & "([Date]) >= [BeginningDate]"
strCriteria = strCriteria & &quot; and &quot; & &quot;([Date]) <= [EndingDate]&quot;
strField = Me![Combo18]
strSearch = strField
strSearch = strField & &quot; like &quot; & strCriteria
Forms!Search.FilterOn = True
Forms!Search.Filter = strSearch

Thanks....
 
I assume Combo18 has field names in it and the match you are looking for starts with the text in combo28:
(NOTE: Try using meaningful names for controls e.g. cboFields)

strFilter = &quot;[&quot; & Combo18.text & &quot;] LIKE '&quot; & Combo28.text & &quot;*' AND ([Date]) >= [BeginningDate] AND ([Date]) <= [EndingDate]&quot;

M :)
 
I tried the above suggestion and recieved the following message when I initiate the click event.

&quot; You can't reference a property or method for a control unless the control has the focus &quot;

I think the original reason I had put the combobox.text into variables is for this reason. I declare the variables as global. Any suggestions...

Thanks again
 
I figured it out!! Without trying the variables in place of the combo.text I replied to the above message. Thanks again..
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top