Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to Access Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Query IN
Shannon Duncan 
  
2 years ago
Having trouble passing an in-list string to a query.

In my Form I have a text box that is updated as the user selects values. They can then "Process" those values. When they click "Process" it loads a sub-form so they can assign some attributes to those values. That all works, and my SQL update works as well.

One of the complaints is that they want a list box to show data from the table for reference.

So, I created a query where I passed the string from the text box to an "IN" criteria in the query. This query populates a list box.

Textbox values = 'value1','value2','value3'

Query is setup like: IN ([Forms]![Form]![TextBox])

Through testing, it works if I only send one variable and remove the "'"

It appears it's doing SELECT * FROM dbo.table WHERE VALUE IN ("value1")

So, I updated the textbox to use double quotes instead of a single quote.

SELECT * FROM dbo.table WHERE VALUE IN ("value1","value2")

It fails. What am I doing wrong?
Juan C Rivera  @Reply  
            
2 years ago
Not sure I am thinking of value1 and/or value2 might get the result... but I recommend this video may not be the exact condition but will point you in the right direction.  let me know if this works out for you.
Multi-Field Find
Shannon Duncan OP  @Reply  
  
2 years ago
Thank you for the suggestion Juan. Unfortunately a "like" statement won't work in this instance.

I was hoping it was just a syntax issue. I may have to build out a looping SQL statement to populate out all the OR statements.

ID = "1"
or
ID = "2"
or
ID = "3"

I'd rather do (ID in ('1','2','3')) but it appears it's wrapping the data in a double quotes for the IN statement when it passes it onto the SQL statement so it ends up being ID in ("'1','2','3'") which returns nothing. If I only pass it 1 value it returns a result.
Kevin Yip  @Reply  
     
2 years ago
Hi Shannon, items enclosed in square brackets [] are "parameters" in a query, and each parameter can only contain one value, not multiple values that you try to use.  The value list for the IN operator needs multiple values separated by commas, but your parameter [Forms]![FormName]![ControlName] can only store one value.  Even if you put commas in there like you did, the whole thing is always treated as one item.  And that is why it doesn't work for you.  To use multiple values the way IN is intended to use, you need to actually feed multiple items to it.  One way is to use string concatenation in VBA.  For instance:

     Dim s As String, sqltext As String
     s = "'one', 'two', 'three'"
     sqltext = "SELECT * FROM Table1 WHERE Field1 IN (" & s & ");"

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Access 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: 4/30/2026 3:20:51 PM. PLT: 0s