The quotes are supposed to be there.
You sure there aren't spaces or something like that in the query name?
--
Doug Steele, Microsoft Access MVP
(no private e-mails, please)
Unless there aren't supposed to be the quotation marks, the name below
(qryNestMasterA) is the name of the query that the list box should be
passing
the values to.
:
From the error message, I'd have to say yes, you did get the query
name
wrong. Unfortunately, only you can determine what the correct name is
it.
--
Doug Steele, Microsoft Access MVP
(no private e-mails, please)
Sorry,
Like I said, I know virtually nothing about SQL. The WHERE clause I
pasted
in below is what I would get when I view the query itself in SQL
view.
What it is doing is asking if the user input anything into the form
(if
null
-> yield everything) then testing if the value entered into the
listbox
(previously a combo box) matches the values in the source table.
With that said, I tried putting the code below into the form itself
attached
to the listbox and set to run on LostFocus. When it runs I get
"Run-Time
Error 3265: Item not found in this collection." And when debugging
it
is
highlighting
Set qdfCurr = CurrentDb.QueryDefs("qryNestMasterA")
Did I enter the query name in wrong? If not what am I doing wrong?
Thanks again,
MonT
:
Your existing Where clause makes no sense to me.
I'm assuming lbDistrictID is the listbox on form frmMyForm. I'll
further
assume that DistrictID is a numeric field.
You need to have code like the following:
Dim qdfCurr As DAO.QueryDef
Dim strDistricts As String
Dim strSQL As String
Dim varSelected As Variant
strSQL = "SELECT DistrictID, StoreID " & _
"FROM tblMasterStoreTable "
If Me![lbDistrictID].ItemsSelected.Count > 0 Then
For Each varSelected In Me![lbDistrictID].ItemsSelected
strDistricts = strDistrict &
Me![lbDistrictID].ItemData(varSelected) &
", "
Next varSelected
' Remove the extraneous ", " from the end
strDistricts = Left(strDistricts, Len(strDistricts) - 2)
strSQL = strSQL & "WHERE DistrictID IN (" & strDistricts & ")"
End If
Set qdfCurr = CurrentDb.QueryDefs("NameOfQuery")
qdfCurr.SQL = strSQL
--
Doug Steele, Microsoft Access MVP
(no private e-mails, please)
message
Thanks Doug,
This looks perfect but I still have one huge problem: while I'm
decent
at
VBA, I don't understand SQL worth anything.
The VBA code it refers to is relatively straightforward, but what
I
don't
understand is how you would link the query's SQL WHERE statement
to
a
command
on the form in such a way that it passes the results back into
the
query.
As it stands the SQL Statement reads as follows:
SELECT tblMasterStoreTable.DistrictID,
tblMasterStoreTable.StoreID
FROM tblMasterStoreTable
WHERE
(((tblMyTable.DistrictID)=IIf(IsNull([Forms]![frmMyForm]![lbDistrictID]),[DistrictID],IIf(([DistrictID]=[Forms]![frmMyForm]![lbDistrictID]),[DistrictID]))));
Thanks Again,
MonT
:
No. Combo boxes are restricted to single-select.
List boxes allow multi-select, but you can't simply refer to a
multi-select
list box as a parameter. You need to dynamically alter the SQL
of
the
query,
as shown in
http://www.mvps.org/access/forms/frm0007.htm at "The
Access
Web"
--
Doug Steele, Microsoft Access MVP
(no e-mails, please!)
message
I am working on a form driven database that primarily works as
an
advanced
filtering system.
One of the main drawbacks to the system as it stands is that
the
user
must
currently run seperate queries/reports if they wish to select
more
than
one
option from a drop down combo box.
Is there a way to allow the user to multiple select items from
the
drop
down?