Combo Box to Specify Search Criteria

G

Guest

I am trying to make a search form with a combo box (to select field) and a
text box (to type in criteria). The combo box is a drop-down specifying
which field in a table the criteria will reference. The search will open a
report.

Right now my report is sourced from a query that just selects all fields
from the table (with criteria to be decided).

I guess my question is, how do I get the query criteria to take into account
what field the drop down menu is specifying, and then have the field be
searched with a certain criteria entered by the user.

Thanks
 
A

Allen Browne

See:
Find as you type - Filter forms with each keystroke
at:
http://allenbrowne.com/AppFindAsUType.html

You can basically copy'n'paste from the sample database to get this working.
No code to write; just one property to set.

Once you have the search form working, you can then apply the Filter of the
form as the WhereCondition for OpenReport. The code would be like this:
Dim strWhere As String
If Me.FilterOn Then
strWhere = Me.Filter
End If
DoCmd.OpenReport "Report1", acViewPreview, , strWhere

(If you are filtering by combo boxes where the bound column is hidden, in
Access 2002 or later, you may need to craft the query for the report in a
special way so it matches the way these versions filter the form.)
 
G

Guest

Thank you Allen that works perfectly

Allen Browne said:
See:
Find as you type - Filter forms with each keystroke
at:
http://allenbrowne.com/AppFindAsUType.html

You can basically copy'n'paste from the sample database to get this working.
No code to write; just one property to set.

Once you have the search form working, you can then apply the Filter of the
form as the WhereCondition for OpenReport. The code would be like this:
Dim strWhere As String
If Me.FilterOn Then
strWhere = Me.Filter
End If
DoCmd.OpenReport "Report1", acViewPreview, , strWhere

(If you are filtering by combo boxes where the bound column is hidden, in
Access 2002 or later, you may need to craft the query for the report in a
special way so it matches the way these versions filter the form.)
 

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