Using a combo box to select which query to run (1 Viewer)

dal1503

Registered User.
Local time
Today, 11:12
Joined
Apr 14, 2016
Messages
34
I have about 20 queries that a user would need to run, but I want to give them a more user-friendly way of running them, rather than selecting the query manually from the navigation pane. One option I've thought of is to have a combo box that lists all the queries, and when the user selects the name of the query from that list it triggers and runs that particular query.

I've seen a few examples of how to achieve similar things but something is missing and I can't quite figure out how to do it.

So far I've created a table that contains fields [QueryID], [QueryName] and [Query Description].

The Record Source for the combo box is as follows:

Code:
SELECT tblQueries.QueryID, tblQueries.QueryName
FROM tblQueries
ORDER BY tblQueries.[QueryName];

In the event procedure of the combo box, in the After Update property I've attempted some sort of code as follows:

Code:
Private Sub Combo0_AfterUpdate()
    DoCmd.OpenQuery =QueryName, acViewNormal, acEdit
End Sub

where 'QueryName' would be whatever query the user selected from the combo box list.


This code obviously doesn't work, but am I along the right lines? Or should I be using a completely different approach?

Thanks
 

Ranman256

Well-known member
Local time
Today, 07:12
Joined
Apr 9, 2015
Messages
4,337
You don't need queryID field, instead use Caption.
User sees caption, but runs the queryName.
In the combo ,set the column widths = 1;0
Set the bound column = 2
Then AFTERUPDATE code is
Docmd.openquery cboBox
 

dal1503

Registered User.
Local time
Today, 11:12
Joined
Apr 14, 2016
Messages
34
You don't need queryID field, instead use Caption.
User sees caption, but runs the queryName.
In the combo ,set the column widths = 1;0
Set the bound column = 2
Then AFTERUPDATE code is
Docmd.openquery cboBox

This worked, thanks!
 

Users who are viewing this thread

Top Bottom