Combo selection

texasalynn

Registered User.
Local time
Today, 17:29
Joined
May 30, 2002
Messages
47
I'm trying to create a form that will let the user select which query to run from the combo box? How do I do that? Whenever I select the combo box it wants me to pick only one. Do I have to do something else; maybe to put all the query names in a table? As you can tell this is new to me and I'm at a loss how to go about this.

Thanks . . . texasalynn
 
You can easily create a combo box on a form to list queries that users can run. I'd suggest though, that you use a list box rather than a combo box if you don't need it to drop down. A combo is best used when you want a user to be able to input an item that doesn't already exist in the combo box.

Anyway, yes, you should probably place the query names that you want the users to be able to run into a table. Then you can fill the listbox with the query name field.

You can then open/run the query when a user clicks or double-clicks on it using code like this into the appropriate event handler:
DoCmd.OpenQuery Me.cboQueryList
 
Why are you trying to run more than one query at a time?
 
Wow - I'm not. What I said is I want a user to select from a combo box which query to run.
 
texasalynn said:
Wow - I'm not. What I said is I want a user to select from a combo box which query to run.

What you said was that it only allows you to select one - implying that you want to select more than one query from the combobox.

If you have used the naming conventions that are commonly used in Access then your queries will all be prefixed with qry ie. qryStaff, qryWeeklyStats, etc.

This way, you can make the RowSource of your combobox:

SELECT DISTINCTROW Mid([Name],4) AS QueryName
FROM MSysObjects
WHERE ((Left([Name],3)="qry"));

Then, in the AfterUpdate() event of your combobox you can put the code:

Code:
DoCmd.OpenQuery "qry" & Me.cboYourCombo.Column(0)
 
Mile-O-Phile's suggestion is a good one. If you don't want users accessing all the queries in your database, be sure to name them with something other than "qry" as the prefix.

I had a similar situation in a database I recently created. I thought it best to set up a special table with query names I would allow users to run. That way, I wouldn't accidentally allow the users to run a query just by having named it using the "qry" prefix.
 

Users who are viewing this thread

Back
Top Bottom