Use List Box to select a paramter for a query

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



For the first time I'm trying to base a query on a user selection via a
list box. My simple test db has one table, two forms and two queries.

Tbl_1 contains four records, two fields:
1 abc
2 def
3 ghi
4 jkl

Frm_1 contains a single text box "Text1" in which I can enter anything
I like.
Qry_1 has the two fields from Tbl_1 with the criterion for the second
field being
Like "*" & [Forms]Frm_1![Text1] & "*"

The SQL is:
SELECT Tbl_1.Field1, Tbl_1.Field2
FROM Tbl_1
GROUP BY Tbl_1.Field1, Tbl_1.Field2
HAVING (((Tbl_1.Field2) Like "*" & [Forms]![Frm_1]![Text1] & "*"));

Opening Frm_1 and typing "b" produces "1 abc" in Qry_1, exactly as
expected.

Frm_2 contains a single list box "List0" based on Tbl_1 with the key
field hidden. The correct four fields show in the list box when Frm_2
is run.
Qry_2 is the same as Qry_1 but with Field 2 criterion changed to
Like [Forms]Frm_2![List0]

Qry_2's SQL is
SELECT Tbl_1.Field1, Tbl_1.Field2
FROM Tbl_1
WHERE (((Tbl_1.Field2) Like [Forms]![Frm_2]![List0]));

No matter what I select in Frm_2, running Qry_2 produces a null result.
(Frm_2 is open at the time)

This is so similar to Joanna's query that John Vinson answered a few
minutes ago that I must have missed something blindingly obvious. Can
anyone suggest what I might have done wrong?

TIA

John

.



Relevant Pages

  • Re: Run Query from Form
    ... Here is what my sql reads as requested. ... working even the first time that i push the button) but my code of the ... > Try switching to the SQL view and post your SQL statement of your query. ... > Jeff wrote: ...
    (microsoft.public.access.queries)
  • Re: How to make the SQL to run longer?
    ... To reproduce one of our cusotmer's probem, I need to make the SQL to ... If you just need a query, any query, that will run for more than a minute so that your app can hang, then you can easily create one. ... Then add the query to your reporting app. ... By the way...this is the first time I've ever heard of someone asking to make things take longer! ...
    (comp.databases.oracle.server)
  • Re: someone help
    ... >first time I am creating SPs.. ... You describe your query as if you were writing a Cobol ... That's not how SQL works. ... A few well-chosen rows of sample data, ...
    (microsoft.public.sqlserver.clients)
  • Re: Weird one.
    ... The first time a query runs, ... "Execution Plan Caching and Reuse" in SQL Server Books Online for more ...
    (microsoft.public.dotnet.languages.vb)
  • table partitioning
    ... the objective is that when one user gets a record, the second user does ... currently i am doing this through asp code, i wish to do it through sql ... query instead. ...
    (microsoft.public.sqlserver.clients)