View Full Version : How to create a parameter query where the criteria are chosen from a combo box?


keeling1
06-08-2009, 07:17 AM
This is a very simple question, I think. And I'm very much a beginner at Access. But can somebody help me set up a parameter query where the prompt allows the user to only choose from a few select options, rather than having the user enter the information manually?

Basically, I want the query to list data for a particular team. The teams are listed in a table called tblTeams. But I don't want the user to enter the team names manually. I want the prompt to give a combo box which lists the team names from tblTeams.

I've created a form that looks like a dialog and has a combo box called cboTeams, thinking that that might be the way to go. But I don't know how to integrate the form into the query.

Can anyone help?

neileg
06-08-2009, 07:32 AM
In the criteria row of the query put
Forms!NameOfYourForm!cboTeams

Note that you should run the query from the form as you can't do it the other way round.

pbaldy
06-08-2009, 07:32 AM
In the criteria:

Forms!FormName.ComboName

You can right-click in the criteria and choose Build, which will let you navigate to it.

keeling1
06-08-2009, 07:41 AM
Thanks neileg and pbaldy for your quick replies. I've done what you've suggested. But the query isn't working properly. In order to get the form to open the query I added this to After Update Events of the combo box:

Private Sub cboTeam_AfterUpdate()
DoCmd.OpenQuery "qryOpenTagsByTeam", acViewNormal, acEdit
DoCmd.Close acForm, "frmTeams"
End Sub

But it's not working. Please help!

gemma-the-husky
06-08-2009, 07:46 AM
in your query

qryOpenTagsByTeam

you need a reference to the combobox in the criteria column, to limit the query results

something like

forms!myform!mycombobox

pbaldy
06-08-2009, 08:11 AM
The form needs to be open while the query is.