0
votes

I have a form in Access 2010 with a number of queries existing in the same Database. I've created a combo box which provides a list of all of the query names using SQL in the Row Source box in the property sheet:

SELECT m.[name] FROM msysobjects AS m WHERE m.type=5 and m.name not alike "~%" ORDER BY m.name; 

The Row/Source type is set to 'Table/Query' and the Bound column is set to '1'. I have also created a command button which I want to link to the combo box (currently called 'Run').

What I'm looking to do is for the command button to run whichever query name the user selects from the Combo Box list, however I'm unsure how this would be achieved. I believe it may require some VBA which I'm not experienced in unfortunately.

I have tried to link the command button directly to the Combo Box however have been unsuccessful, as above I believe this may require some sort of VBA code.

Any help on the above would be really appreciated.

1
Are these SELECT queries (where you want to open the datasheet) or UPDATE queries (that you want to execute)? - Andre
Hi @Andre , they are just SELECT queries where I want to open the datasheet. Hope that helps. - Stewillo1

1 Answers

1
votes

Just use the On Click event of the button (use the "..." button to build an event procedure):

Private Sub cmdRun_Click()

    DoCmd.OpenQuery Me.cboQuery.Value

End Sub

Adapt control names to your form.