Using IN an NOT IN FUNCTION ON TH FLY

  • Thread starter Thread starter JJP
  • Start date Start date
J

JJP

I use the IN FUNCTION in my query to filter specific product configurations.
For example,
In(WFM7120,WFM7120HD,WFM7120PHY)

I would like to be able to change the products on the fly using something
like the [ENTER] function, but I cannot figure out how to do it. Can anyone
suggest a method for doing this?
Thanks,
 
In design view add a calculated field --
Input_List: [Enter items separated by space]
In criteria row put --
Like "*" & [YourTable].[Product] & "*"
 
this is some code posted by tom

WHERE InStr("," & [Enter List: ] & ",", "," & [SomeColumn] & ",") > 0

this is some code posted by michel

WHERE ( "," & [parameter] & "," ) LIKE "*[ ,]" & FieldName
& "[ ,]*"

so to use the above you need to enter the value as a comma delimited
list

WFM7120,WFM7120HD,WFM7120PHY

and it should search for it

so to enter this into query designer

expression: "," & [parameter] & ","

criteria: LIKE "*[ ,]" & FieldName & "[ ,]*"

hope this helps

Regards
Kelvan
 
Karl, maybe you can help a little further. Your formula did work but I
probably stated my case poorly.

Considering the following database structure:
OrderNumber
Item
QTY
Price


There can e a variety of Items in the Item Field such as:
(WFM7120, WFM7120EYE,WFM7120AD, WFM7120DDE,WFM7120HD,WFM7120PHY, etc.)

Ideally I want to find all the orders that contain for Example WFM7120HD,
WFM7120AD and WFM7120EYE) The order should contain all three. Using the
formula (Like "*" & [qryall].[Item] & "*") along the lines you suggest I see
orders that have on either WFM7120HD or WFM7120AD or WFM7120EYE).

Once I filter on orders that have all three, I would like to see the ENTIRE
ORDER and quanties and prices. I can do that by creatring a second query
that relates the order numbers from the fist filtering query to the
underlying database.

Any suggestions would be appreciated.
Thanks,



KARL DEWEY said:
In design view add a calculated field --
Input_List: [Enter items separated by space]
In criteria row put --
Like "*" & [YourTable].[Product] & "*"
--
KARL DEWEY
Build a little - Test a little


JJP said:
I use the IN FUNCTION in my query to filter specific product configurations.
For example,
In(WFM7120,WFM7120HD,WFM7120PHY)

I would like to be able to change the products on the fly using something
like the [ENTER] function, but I cannot figure out how to do it. Can anyone
suggest a method for doing this?
Thanks,
 
i am not sure if thats actually possible using a query you would have
to build a form i think to get the criteria and then filter the query
based on that.

Regards
Kelvan
 
Looks as if you need a subquery. The subquery will identify the order numbers
you are interested in and the main query will return the entire record for
those order numbers.

SELECT *
FROM qryall
WHERE OrderNumber In
(SELECT OrderNumber
FROM qryall
WHERE " " & [Enter items separated by space] & " " Like "* " &
[qryall].[Item] & " *")

John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County
Karl, maybe you can help a little further. Your formula did work but I
probably stated my case poorly.

Considering the following database structure:
OrderNumber
Item
QTY
Price


There can e a variety of Items in the Item Field such as:
(WFM7120, WFM7120EYE,WFM7120AD, WFM7120DDE,WFM7120HD,WFM7120PHY, etc.)

Ideally I want to find all the orders that contain for Example WFM7120HD,
WFM7120AD and WFM7120EYE) The order should contain all three. Using the
formula (Like "*" & [qryall].[Item] & "*") along the lines you suggest I see
orders that have on either WFM7120HD or WFM7120AD or WFM7120EYE).

Once I filter on orders that have all three, I would like to see the ENTIRE
ORDER and quanties and prices. I can do that by creatring a second query
that relates the order numbers from the fist filtering query to the
underlying database.

Any suggestions would be appreciated.
Thanks,



KARL DEWEY said:
In design view add a calculated field --
Input_List: [Enter items separated by space]
In criteria row put --
Like "*" & [YourTable].[Product] & "*"
--
KARL DEWEY
Build a little - Test a little


JJP said:
I use the IN FUNCTION in my query to filter specific product configurations.
For example,
In(WFM7120,WFM7120HD,WFM7120PHY)

I would like to be able to change the products on the fly using something
like the [ENTER] function, but I cannot figure out how to do it. Can anyone
suggest a method for doing this?
Thanks,
 
You can use a subquery which counts the order lines where the item is in the
value list. If the count equals the number of items then the order contains
all three items, e.g. using the Northwind Order Details table as an example:

SELECT *
FROM [Order Details] AS OD1
WHERE
(SELECT COUNT(*)
FROM [Order Details] AS OD2
WHERE OD2.OrderID = OD1.OrderID
AND ProductID IN(1,2))=2;

which returns all orders containing products 1 and 2 (Chai and Chang),
whereas:

SELECT *
FROM [Order Details] AS OD1
WHERE
(SELECT COUNT(*)
FROM [Order Details] AS OD2
WHERE OD2.OrderID = OD1.OrderID
AND ProductID IN(1,2,3))=3;

returns no orders as none contain product 3 (Aniseed Syrup) in addition to 1
and 2.

By adding the following module, from the link I gave in my earlier reply, to
the database:

'''''''''Module Begins'''''''''''
Option Compare Database
Option Explicit
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Function GetToken(stLn, stDelim)

Dim iDelim As Integer, stToken As String
iDelim = InStr(1, stLn, stDelim)
If (iDelim <> 0) Then
stToken = LTrim$(RTrim$(Mid$(stLn, 1, iDelim - 1)))
stLn = Mid$(stLn, iDelim + 1)
Else
stToken = LTrim$(RTrim$(Mid$(stLn, 1)))
stLn = ""
End If
GetToken = stToken

End Function
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Function InParam(fld, param) As Boolean

Dim stToken As String
If IsNull(fld) Then fld = ""
Do While (Len(param) > 0)
stToken = GetToken(param, ",")
If stToken = LTrim$(RTrim$(fld)) Then
InParam = True
Exit Function
Else
InParam = False
End If
Loop

End Function
'''''''''Module Ends'''''''''''

You can include parameters in the query:

SELECT *
FROM [Order Details] AS OD1
WHERE
(SELECT COUNT(*)
FROM [Order Details] AS OD2
WHERE OD2.OrderID = OD1.OrderID
AND InParam(ProductID,[Enter product ID list:]))
=[Enter number of products:];

By entering 1,2 at the first prompt and 2 at the second the result would be
the same as the first query above. The InParam function is not the fastest
thing on two wheels but with the 2000+ rows in the Northwind table
performance is acceptable.

In a developed application you'd not use simple parameter prompts like this
of course, but probably a form with a multi-select list box in which the
products would be selected by name and whose AfterUpdate event procedure
would be used to fill (a) a hidden text box on the form with a
comma-separated value list of the corresponding OrderID values., and (b)
another hidden text box with the list box's ItemsSelected.Count value. The
two hidden text boxes would then be referenced as the parameters by the
query.

Ken Sheridan
Stafford, England

JJP said:
Karl, maybe you can help a little further. Your formula did work but I
probably stated my case poorly.

Considering the following database structure:
OrderNumber
Item
QTY
Price


There can e a variety of Items in the Item Field such as:
(WFM7120, WFM7120EYE,WFM7120AD, WFM7120DDE,WFM7120HD,WFM7120PHY, etc.)

Ideally I want to find all the orders that contain for Example WFM7120HD,
WFM7120AD and WFM7120EYE) The order should contain all three. Using the
formula (Like "*" & [qryall].[Item] & "*") along the lines you suggest I see
orders that have on either WFM7120HD or WFM7120AD or WFM7120EYE).

Once I filter on orders that have all three, I would like to see the ENTIRE
ORDER and quanties and prices. I can do that by creatring a second query
that relates the order numbers from the fist filtering query to the
underlying database.

Any suggestions would be appreciated.
Thanks,



KARL DEWEY said:
In design view add a calculated field --
Input_List: [Enter items separated by space]
In criteria row put --
Like "*" & [YourTable].[Product] & "*"
--
KARL DEWEY
Build a little - Test a little


JJP said:
I use the IN FUNCTION in my query to filter specific product configurations.
For example,
In(WFM7120,WFM7120HD,WFM7120PHY)

I would like to be able to change the products on the fly using something
like the [ENTER] function, but I cannot figure out how to do it. Can anyone
suggest a method for doing this?
Thanks,
 
Suppose I change the approach by using a CrossTab Query to get the following
fields: qryAllSelect1

Order Number WFM7120HD WFM7120AD WFM7120EYE WFM7120 DDE WFM7120CPS........

They a 2nd query qrAllSelect2 as the parent and qryAllSelect1 as the child.

I have done this and if I manually put NOT NUll in WFM7120AD and WFM7120EYE
I get all the records that have both the AD and EYE option.

I can then use this query as a pointer to link t the main database to show
only those records tha have the AD & EYE Option, but still see the full
order.

Is there a way to enter the NOT NULL in on the fly?

Thanks,
 
Back
Top