Every act of conscious learning requires the willingness to suffer an injury to one's self-esteem. That is why young children, before they are aware of their own self-importance, learn so easily.
Hi there - I appreciate you guys fortaking a peak at this and offering any advice..
I have a Query that takes in all our inventory items based on the location that is entered..[Enter Location #:] however, we have inventory that is in multiple locations for example 20 chairs at location 1,3,9. I also have a "desk" among other iteams at location 3. When I run the query and enter location "3" it returns all the items at location "3" like the desk; however I need it to also return the items that are listed in multiple locations like the "chairs" not just the ones that have the "location field" only listed as location "3" but also "1,3,9" because it contains a "3" as a location. Any help would be greatly appreciated. I am using the default query builder not any programming.
Kevin Robertson
@Reply 3 years ago
Try this:
InStr([Enter Location #:],[Location])>0
Kevin Yip
@Reply 3 years ago
If "1,3,9" is text, then InStr() or any method to search text within the field won't work, because searching for "3" would return not just "3" or "1,3,9", but also anything that has a "3" in it: "23", "33", "43", "13,30,1", "1,33,300", etc.
If you want to search for "3" and only get "3", but not "13", "23", "33", "300", etc., then this is not as straightforward as it appears to be. The key is the *comma*, the delimiter, that separates the different locations, so that "3" wouldn't be confused as "13", "23", etc., because the commas always separate them apart.
You first need to make sure you use only commas as the delimiters in all entries. Then you separate the different locations with the Split() function. For instance, Split("1,3,9", ",") returns an *array* containing "1", "3", and "9" individually.
Finally, you compare your lookup value against all the values in the array and see if there is a match. The VBA code for this is not terribly difficult, but quite involved if you are a beginner in VBA.
If I were in your position, I would not lump all the locations together in one field. Instead, I would store each location "individually*, in a normalized table such as this:
Being "normalized" means that things that should be separate, should be.
This would make the query a lot more straightforward, and you probably wouldn't need VBA. You could have a query that joins your location table with your main product table, with a WHERE clause that could easily find all products that are at location 3:
SELECT * FROM ProductsT
INNER JOIN LocationsT ON ProductsT.ProductID = LocationsT.ProductID
WHERE LocationsT.LocationNum = "3"
Kevin Robertson
@Reply 3 years ago
I just tested what I posted above and it does work.
The available values in the table: 3, 1, 43, 9, 5, 3, 23
In the parameter dialog I entered: 1,3,9
What was returned: 3, 1, 9, 3
Kevin Yip
@Reply 3 years ago
But if you enter "3" as the parameter (which Luis said he was doing), your Instr() function will return 3, 43, and 23, if they are all text. I assume they are text because Luis said that his location field can contain something like "1,3,9" -- which is a non-normalized way to store this info.
Sorry, only students may add comments.
Click here for more
information on how you can set up an account.
If you are a Visitor, go ahead and post your reply as a
new comment, and we'll move it here for you
once it's approved. Be sure to use the same name and email address.
This thread is now CLOSED. If you wish to comment, start a NEW discussion in
Visitor Forum.