Re: Multiple combo boxes - send parameters to a query?
- From: Marshall Barton <marshbarton@xxxxxxxxxx>
- Date: Thu, 19 Jan 2006 11:53:47 -0600
Richard Horne wrote:
>Hi Marshall - I think I might have solved this problem.
>
>First though, I think Like "*" & [cboWhatever] & "*" is used to put *wild
>card onto either end of a field, I've just been researching wild cards and
>their normal usage is *searchterm* but when I tried *[cboWhatever]* no
>results were found, however using "*" & [cbo] & "*" seems to work.
>
>Anyway, I've just discovered the Nz function and I think might well solve my
>problem, I have modified my query and it now reads:
>
>
>SELECT Orders.OrderNumber, Orders.[Customer Name], Orders.[Order Date],
>Order_Details.[Item Number], Order_Details.[Item Type],
>Order_Details.Description, Order_Details.Type_Colour_Size,
>Order_Details.Quantity, Order_Details.Price, Order_Details.Denomination,
>Order_Details.Department, Orders.Complete
>FROM Orders INNER JOIN Order_Details ON Orders.OrderNumber =
>Order_Details.OrderNumber
>WHERE (((Orders.[Customer Name]) Like Nz([cboQueriedCustomer],"*"))
>AND ((Order_Details.[Item Type]) Like Nz([cboProduct],"*"))
>AND ((Order_Details.Description) Like "*" & [txtDescription] & "*")
>AND ((Order_Details.Type_Colour_Size) Like "*" & [txtTypeColourSize] & "*")
>AND ((Orders.Complete) Like Nz([cboOrder_Complete],"*"))
>AND ((Orders.[Customer's Order Number]) Like "*" & [QueriedCustRef] & "*")
>AND ((Orders.Contact) Like Nz([cboQueriedContact],"*")))
>ORDER BY Orders.OrderNumber DESC;
>
>This seems to work, but can you see any flaws to this methodology? I ask
>because people keep telling me my query can't be done the way I want it but
>the above seems to be working. I just need to verify my query's results by
>manually comparing with the data in my table.
This is a tough question. Logically, I think that your
approach makes sense. However, the Like operator uses
string operands so numeric and date fields will either fail
or first go through a conversion process before Like can do
its thing. It has been a very long time since I last used
Like Nz(xxx,"*") to match any value, but it did work at that
time. Note that it is inefficient and may be too slow in
some situations, but only you can decide if it's acceptable.
I think you should go with this until you run into a problem
with it, then maybe you will see more sophisticated
alternatives.
One thing you have that I find extraordinay is that you are
referencing form controls without specifying the full
reference. I would have expected the query to prompt you to
enter values for [cboQueriedCustomer], [cboProduct], etc.
If those really are controls on a form where users enter the
criteria values, then the book says the references should be
Forms!nameofform.cboQueriedCustomer,
Forms!nameofform.cboProduct, etc.
Your reason for using "*" & xxx & "*" makes sense, but it is
not what I was questioning. The syntax I was questioning
was where your earlier query had a couple of conditions that
were "*" & xxx without "*" on the right, which, when xxx
is not null, will only match records that end in the xxx
string. Now, with your use of Nz, you are not trying to do
those odd partial matches so it is no longer a question.
--
Marsh
MVP [MS Access]
.
- Follow-Ups:
- Re: Multiple combo boxes - send parameters to a query?
- From: John Spencer
- Re: Multiple combo boxes - send parameters to a query?
- References:
- Re: Multiple combo boxes - send parameters to a query?
- From: Marshall Barton
- Re: Multiple combo boxes - send parameters to a query?
- From: Marshall Barton
- Re: Multiple combo boxes - send parameters to a query?
- From: Marshall Barton
- Re: Multiple combo boxes - send parameters to a query?
- From: Marshall Barton
- Re: Multiple combo boxes - send parameters to a query?
- Prev by Date: Re: Merge different rows to same column in Access
- Next by Date: Re: Most Current Rev Only
- Previous by thread: Re: Multiple combo boxes - send parameters to a query?
- Next by thread: Re: Multiple combo boxes - send parameters to a query?
- Index(es):
Relevant Pages
|