you will probably have to Write VBA code to do that.<br><br>Look at Listbox in Help<br>there is a .selected property and a .listcount <br>here is a simple example to get you started.<br>-----------------------------<br>Private Sub Command1_Click()<br> dim a as integer<br> For a = 0 To List1.ListCount - 1<br> If List1.Selected(a) = True Then<br> Debug.Print "Got it"<br> End If<br> Next<br> ' this will let you know how many were selected<br> Debug.Print List1.SelCount<br>End Sub <p>DougP<br><a href=mailto: dposton@universal1.com> dposton@universal1.com</a><br><a href= > </a><br> Ask me how Bar-codes can help you be more productive.
Access does not allow a query to see a multi-selected Listbox that's why I said use VBA.<br><br>How many selected items are we talking about 10? 20? 9000?<br><br>using VBA you can create a string Like:<br>Item1 And Item3 AND Item4 and Item8<br>where Item# is the list selection and VBA puts the word "AND" or "OR" in between then your query looks at a text box that has all of tha in it.<br> <p>DougP<br><a href=mailto: dposton@universal1.com> dposton@universal1.com</a><br><a href= > </a><br> Ask me how Bar-codes can help you be more productive.
This works if the Bound Column is the one which has your data in it. >>>>>List1.ItemData(a)<br><br><br>--------------------------------<br>Private Sub Command2_Click()<br> Dim a As Integer<br> Dim QryString As String<br> For a = 0 To List1.ListCount - 1<br> If List1.Selected(a) = True Then<br> <br> QryString = QryString & List1.ItemData(a) & " AND "<br> Debug.Print "Got it"<br> End If<br> <br> Next<br> QryString = Left(QryString, Len(QryString) - 5)<br> ' this will let you know how many were selected<br> Debug.Print QryString<br>End Sub<br>-----------------------<br> <p>DougP<br><a href=mailto: dposton@universal1.com> dposton@universal1.com</a><br><a href= > </a><br> Ask me how Bar-codes can help you be more productive.
One thing I forgot to mention<br>Below the QryString = Left(QryString ...<br>Put your Text box name like so<br><br>Me!Text1 = QryString <br><br>Then in your query put this in the Criteria of the field you want to see the Listboxes selected items.<br><br>[Forms]![Formname]![Text1]<br><br>So your Query will reflect the selections made in the list box. <p>DougP<br><a href=mailto: dposton@universal1.com> dposton@universal1.com</a><br><a href= > </a><br> Ask me how Bar-codes can help you be more productive.
Also after testing my example further I noticed that I had to add single quotes if the items were strings<br>so here is the modifed and tested version<br><br> Dim a As Integer<br> Dim QryString As String<br> For a = 0 To List1.ListCount - 1<br> If List1.Selected(a) = True Then<br> QryString = QryString & Chr$(34) & List1.ItemData(a) & Chr$(34) & " OR "<br> Debug.Print "Got it"<br> End If<br> Next<br> QryString = Left(QryString, Len(QryString) - 4)<br> Text1 = Trim(QryString)<br><br>Notice: that because the Word "OR" is shorter than AND, you subtract 4 characters instead of 5 <br>QryString = Left(QryString, Len(QryString) - 4)<<<<<<<br><br> <p>DougP<br><a href=mailto: dposton@universal1.com> dposton@universal1.com</a><br><a href= > </a><br> Ask me how Bar-codes can help you be more productive.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.