Re: Multi select list boxes to generate query from form



Check http://www.mvps.org/access/forms/frm0007.htm at "The Access Web" for
one approach, although to be honest I prefer to use:

strSQL = "Select * from Employees where [EmpID] In ("
For Each varItem In ctl.ItemsSelected
strSQL = strSQL & ctl.ItemData(varItem) & ", "
Next varItem
strSQL=Left$(strSQL,len(strSQL)-2)) & ")"

Note that if the field is text, you need to include quotes around the value.

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)


"SusanForson" <SusanForson@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:CB0C1D48-F814-48CB-BAF8-E4771BD5A0D2@xxxxxxxxxxxxxxxx
I successfully set up a form to use two multi-select list boxes to generate
a
report using the Northwind example posted for previous inquiries. I would
also like to be able to preserve the query generated in this process so I
can
export the query to Excel (or just generate the query and not the report).

I tried setting up a query to read the form, but am not getting the
criteria
set up correctly to read multiple choices.

Any suggestions? I need help with writing the code.


.



Relevant Pages

  • Re: List Box MultiSelect
    ... Does your query still contain ... Dim varItem As Variant ... Dim strResult As String ...
    (microsoft.public.access.forms)
  • RE: Seeking Help With VBA and SQL Instant Query
    ... Have a button that runs the query and 'ignores' dates, ... Dim blnQueryExists As Boolean ... Dim strBroker As String ... For Each varItem In Me.lstBroker.ItemsSelected ...
    (microsoft.public.access.modulesdaovba)
  • RE: Seeking Help With VBA and SQL Instant Query
    ... Have a button that runs the query and 'ignores' dates, ... Dim blnQueryExists As Boolean ... Dim strBroker As String ... For Each varItem In Me.lstBroker.ItemsSelected ...
    (microsoft.public.access.modulesdaovba)
  • RE: Can ctlRef.ItemData be used conditionally?
    ... Private Function BuildWhereCondition(strControl As String) As String ... Dim varItem As Variant ... First the append query needs to run. ...
    (microsoft.public.access.formscoding)
  • Re: setup a report to pull mutilple peoples data.
    ... Don't put criteria in the query, instead have the report show everything and use use the WHERE clause of the OpenReport action to limit the records ... For Each varItem In listbox_controlname.ItemsSelected ... I have setup the query using the Inexpression in the criteria and that works fine. ...
    (microsoft.public.access.reports)