Combo box for queries

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

Guest

when opening a query that has a set criteria a window opens with text box. Is
it possible to change the text box into a combo box so that the proper query
criteria can be selected rather than typed?
 
This has been answered at least once TODAY. Please search the newsgroups
for your answer before posting a new thread.

You can add a acombobox to a FORM and then use the entry in your query, but
you can't do this directly in your query.

For more details, do a search and read the other posts related to this
topic. Many of them have step-by-step instructions for creating a parameter
form.
 
when opening a query that has a set criteria a window opens with text box. Is
it possible to change the text box into a combo box so that the proper query
criteria can be selected rather than typed?

Adapt this to your needs.

Create an unbound form.
Add a combo box.
Set the Row Source of the combo box to include the
CompanyID field and the Company Name.
Name the Combo Box 'FindCompany'.
Set it's Bound column to 1.
Set it's Column Count property to 2.
Set the Column Width property to 0";1"

Add a Command Button to the form.
Code the button's click event:

DoCmd.OpenQuery "QueryName"
DoCmd.Close acForm, Me.Name

Name this form 'ParamForm'.

As criteria in the query CompanyID field write:
forms!ParamForm!FindCompany

Select the company, click the command button, the query will run.
 
I am trying to expand on your example and have hit a stumbling block. I
was able to duplicate the example fgut gave and have it execute a query.
I want it to execute a report instead. The report executes the query
so the criteria for the query should be the same. The only change I was
expecting to do was instead of DoCmd.OpenQuery was use DoCmd.OpenReport.
That works but the issue I ran into is the actual query. The data
field that I have allows for entry of multiple cancer types. They may
not be in the same sequence or count so I use" like "*" & [Enter cancer
type] & "*". While this works like I charm, I would prefer the combo
box to give the types. Removes the misspelling issue. I tried: like
Like "*" & [forms!FindCancer!FindCancer] & "*". I select the type, the
report executes but the result is a blank report. If I remove [] and
use "" I get everything in the table instead of the desired type. If I
remove Like "*" & components, it generates a blank report. What am I
missing.

Thanks,

Guy
 
Back
Top