On your form your should have a command button and a combobox. The combobox is set to .visible = false. The RowSource for the combobox would be a SQL string that looks something like this example:
Code:
Select A.RouteNumber FROM [i]yourtablename[/i] as A GROUP BY A.RouteNumber ORDER BY A.RouteNumber;
This code would give you one row for every route number in the table and sort by that field. Now you combobox has only valid route numbers for selection.
Make you CmdButton the same width as the combobox and place the command button directly on top of the combobox. The Caption for the command button can be of your choosing.
The OnClick event procedure of the CommandButton would be as follows:
Code:
Me![i]comboboxname[/i].visible = True
Me![i]comboboxname[/i].setfocus
Me![i]comboboxname[/i].dropdown
Me![i]commandbuttonname[/i].visible = False
The AfterUpdate event procedure of the Combobox would be as follows:
Code:
DoCmd.OpenQuery "[i]qryYourQuerynName/i]"
Me![i]commandbuttonname[/i].visible = True
Me![i]commandbuttonname[/i].setfocus
Me![i]comboboxname[/i].visible = True
Me![i]comboboxname[/i].visible = False
We may have a little problem right at the end here. You see the combobox must remain visible with the value picked for the query to run. We have run the query first and then being the housekeeping chore of closing the combobox and setting to visible = false and moving the focus back to the command button. If the query is not done with the combobox it may cause a problem but can be fixed with a global variable and a function. Give it a try this way and if it errors out we will add the additional small amount of code.
You query should use the reference to the combobox on the form for its critieria.
Code:
FORMS![i]formname.comboboxname[/i]
Let me know how this works.
Bob Scriver
[blue]Want the best answers? See FAQ181-2886[/blue]