Question

I have created an access 2010 form where I have a listbox and two command buttons. Listbox includes all of the query names and command button one is for "query print preview" and the command button 2 is for "opening the query" which should be same as "double clicking the query name" in the listbox. So, how do I make these buttons and queries to open when double clicked in the list work?

Was it helpful?

Solution

Edit: I've updated my answer with the generic code you would need to open a query via the button or the Listbox. This assumes that the values in the Listbox are valid query names within your database.

This is easily done with a little VBA.

Option Explicit
Private Sub List_DblClick(Cancel As Integer)
Call Show_Click
End Sub

Private Sub Show_Click()
DoCmd.OpenQuery Me.List.Value
End Sub

This assumes that your listbox is called List. And your command button is called Show.

Basically, the code you want run in the button's Click event and call that sub from the list box's DblClick event.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top