opening query from listbox

G

Guest

Hello. I have a situation in which the users want to open queries in
datasheet view two ways;

1) by double clicking the qry name in a listbox (lstQueriesAvailable)
2) by selecting the qry name from the list and then using a button

I am thinking about this too hard and not seeing what the coding would be
for either. I have opened a single query from a docmd.openquery line before
but this is perplexing.

If anyone has the info, help. Thanks in advance for any assistance.
*** John
 
G

Graham R Seach

John,

How you get the query names into the listbox you haven't said, but assuming
you've already done so...

'Declarations Section
Private varQueryName As Variant

Private Sub MyListBox_Click()
varQueryName = Me.MyListBox
End Sub

Private Sub MyListBox_DblClick()
Call cmdRunQuery_Click
End Sub

Private Sub cmdRunQuery_Click()
If Not IsNull(varQueryName) Then
DoCmd.OpenQuery varQueryName
End If
End Sub

Regards,
Graham R Seach
Microsoft Access MVP
Canberra, Australia
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top