Listbox selection to execute a query

I

Ixtreme

Hi,

I have a listbox that contains a list of all queries I have created.
The rowsource of the listbox control =
SELECT MSysObjects.Name
FROM MsysObjects
WHERE (Left$([Name],1)<>"~") AND
(MSysObjects.Type)=5
ORDER BY MSysObjects.Name;

What I want is to execute the query from the list if the user
doubleclicks on it or clicks a button (Go!) on the same form. Somehow
I can't find an answer to this simple question.
 
D

Dirk Goldgar

Ixtreme said:
Hi,

I have a listbox that contains a list of all queries I have created.
The rowsource of the listbox control =
SELECT MSysObjects.Name
FROM MsysObjects
WHERE (Left$([Name],1)<>"~") AND
(MSysObjects.Type)=5
ORDER BY MSysObjects.Name;

What I want is to execute the query from the list if the user
doubleclicks on it or clicks a button (Go!) on the same form. Somehow
I can't find an answer to this simple question.


You can do something like this:

'----- start of code -----
Sub RunSelectedQuery()

With Me!lstYourListbox
If IsNull(.Value) Then
MsgBox "Please select a query to run."
Else
DoCmd.OpenQuery .Value
End If
End With

End Sub

Private Sub lstYourListbox_DblClick(Cancel As Integer)

RunSelectedQuery

End Sub

Private Sub cmdGo_Click(Cancel As Integer)

RunSelectedQuery

End Sub
'----- end of code -----

In the above example code, I've assumed the listbox is named
"lstYourListbox" and the button is named "cmdGo". You'll want to correct
those names, of course.
 

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