Computer Learning Zone CLZ Access Excel Word Windows

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.

-Thomas Szasz
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to Visitor Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Double Lookup on Parameter
Luis Ochoa 

3 years ago
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:

ProductID   LocationNum
P1000       1
P1000       3
P1000       9
P2000       13
P3000       23
...

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.

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Visitor Forum.
 

Next Unseen

 
New Feature: Comment Live View
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 6/22/2026 12:14:45 AM. PLT: 1s