Can I change which query is run from a button? (1 Viewer)

Anakardian

Registered User.
Local time
Today, 09:52
Joined
Mar 14, 2010
Messages
173
I am working on creating a dashboard for selecting various parameters and then viewing the results.

While I can create a dashboard for each main group I am working with I thought that perhaps you could use a combobox to provide the input for which queries it needs to run to get the desired result.

I am sure a long list of if...then.. could do it but perhaps there is a smarter way?

Would it be possible to make something like this:
DoCmd.OpenQuery "qryMTCountInspectionPerFleetGroup"
The red part should be assigned by a selection in a combobox.

I have the impression it is possible however I cannot find anything similar.
 

VilaRestal

';drop database master;--
Local time
Today, 08:52
Joined
Jun 8, 2011
Messages
1,046
It should be just:

DoCmd.OpenQuery "qryMTCountInspectionPer" & Combo1.Text

Change Combo1 to the name of your combobox
 

Anakardian

Registered User.
Local time
Today, 09:52
Joined
Mar 14, 2010
Messages
173
That sounds like a simple and neat solution.

I will try it out and let you know how it goes.
 

VilaRestal

';drop database master;--
Local time
Today, 08:52
Joined
Jun 8, 2011
Messages
1,046
If it's listed in the combobox as "Fleet Group" then you could replace the space:

DoCmd.OpenQuery "qryMTCountInspectionPer" & Replace(Combo1.Text," ","")

And if there's a more complex relationship between what's shown in the combobox and the names of the queries then it would take some more processing of the text.
 

Anakardian

Registered User.
Local time
Today, 09:52
Joined
Mar 14, 2010
Messages
173
Well I tried the first solution and stumbled as it turned out the combobox insisted on supplying the ID number of the group instead of the text I wanted it to pass on.

I then decided that using the CamelCase version of the group as the primary key should solve that problem. Testing it with a text box reflecting what is stored in the combobox indicates that it works. (The combobox still displays the "normal" text with spaces etc.)

Another post in here solved the run-time error 2185 I then got when I used the following instead:
DoCmd.OpenQuery "qryMTCountInspectionPer" & SelectGraphGroup

I am now referring directly to the combobox and have no need of intermediate steps.

Thank you for the help.
 

Users who are viewing this thread

Top Bottom