running a query based upon a listbox selection

wjulaxer13

New member
Local time
Today, 09:45
Joined
Apr 22, 2015
Messages
9
this is likely very easy but being somewhat new to access listboxes I am having trouble. I have a list box that is correctly listing resources from a table (tblResource). I would like to select one of the list box entry and run a query against the tblResource to show the information for that resource in a form. I have tried to use the lstindex with the control (lstResource) in the where clause of a query to accomplish this with no success. Any ideas for me?
 
What do you mean by show? In the same form? Fill in some fields?
Here is an Example of what I think you are asking.

PHP:
'Append Multiple Email Addresse To EmailTo Field.

  If Me.lstlist.ItemsSelected.Count = 0 Then
    MsgBox "You must select at least 1 Item"
    Exit Sub
  End If


Dim strEmail As String
Dim varItem As Variant
For Each varItem In lstlist.ItemsSelected
            
         strEmail = strEmail & lstlist.Column(2, varItem) & ";"
     
Next varItem
If strEmail > "" Then
  strEmail = Left(strEmail, Len(strEmail) - 1)
  End If


Me.EmailTo.Value = strEmail
 
sorry, let me rephrase. I want to run the query using the listbox selection as a variable in the where clause (where resourcename = ?) and just have it display the results of the query. I may create a form to make it a little prettier latere but just showing the results of the query would be sufficient. I am using access 2013. I hope this helps. As I said, I am somewhat new to Access.
 
Then simply add in our query grid the field in your listbox for the criteria.
And then of course using the OnClickEvent run the query.

HTH
 
ok, i have the code recognizing the correct selected list member. now to get the query to run. would the easiest place to place this code be the unbound listbox or a command button that I created? How does it tie to the query? through vb? Right now I have it as part of the On Click event.
 
Personally, I would use a command button. OnClickEvent
 

Users who are viewing this thread

Back
Top Bottom