Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Database Design / April 2005

Tip: Looking for answers? Try searching our database.

how would i setup a list box with multiselection to run a query

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
mark - 30 Apr 2005 15:28 GMT
i have a query that i need multiple inputs from a form. I know i should use
mult-selection in the form, but how do i transfer my selections to the form
Paul Overway - 30 Apr 2005 17:15 GMT
You need to iterate through the ItemsSelected collection of the listbox and
get all the selected items.  Then you need to either build and assign SQL
for the query, i.e.,

Dim varSelected As Variant
Dim strWhere as String
Dim strSQL as string
Dim db as database
Dim qdf as querydef

   strSQL = "SELECT * FROM SomeTable"

   strWhere = " WHERE [SomeField] In("

   For each varSelected in Me.lstSomeList.ItemsSelected
       strWhere = Me.lstSomeList.ItemData(varSelected) & ","
   Next

   strWhere = Left(strWhere,Len(strWhere)-1) & ")"

   strSQL = strSQL & strWHERE

   Set db = currentdb()
   Set qdf = db.QueryDefs("SomeQuery")

   qdf.SQL = strSQL

...or assign the list of selected items to a hidden text box in a comma
separated format and then use Eval in your query like this,i.e.,

   SELECT * FROM SomeTable WHERE Eval([SomeField] & " In(" &
Forms![SomeForm]![HiddenTextBox] & ")")=True

*this second method will not work if you have Jet Sandbox turned
on....normally, this would only be an potential issue for Access 2003

If the listbox items are text, you need to enclose each item in single
quotes for both method, i..e, the In parameter should look like..

'Item1','Item2','Item3'

Signature

Paul Overway
Logico Solutions
http://www.logico-solutions.com

>i have a query that i need multiple inputs from a form. I know i should use
> mult-selection in the form, but how do i transfer my selections to the
> form
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.