running query from listbox selection

david444

Registered User.
Local time
Today, 21:44
Joined
Mar 11, 2003
Messages
12
if a listbox is created on a form, is it possible that when the user select an item from the listbox, a query is run.
 
You can rub a sub on the listbox's On Click event to run the query.
 
Use the listbox's AfterUpdate() event rather than the OnClick() - clicking anywhere on a listbox starts the latter event, whereas the former runs once data in the list has been selected.
 
can it be set so that a certain selection from the listbox opens a certain query.
 
Are you saying you want it to set the criteria for a query or actually open different queries based on the selection.

I've setup listboxes for people to allow them to choose a report to run. The way I did that was create a table where the first field contained the name of the report and the second was a description. Then I set the listbox bound to the first field but only display the second.

Something like that could work.
 
Yes, it can.

Not sure how you decide which query to run - here's a suggestion.

Code:
Private Sub lstYourListbox_AfterUpdate()

    Select Case Me.lstYourListBox
        Case = "Whatever"
            DoCmd.OpenQuery "ThisQuery"
        Case = "ThisOrThat"
            DoCmd.OpenQuery "ThatQuery"
        Case Else
            DoCmd.OpenQuery "OtherQuery"
    End Select

End Sub
 
Mile-O-Phile

We just can't seem to agree on anything. :D :D
 

Users who are viewing this thread

Back
Top Bottom