|
-
Apr 8th, 2010, 07:47 PM
#1
Thread Starter
Fanatic Member
[RESOLVED] SQL IN WHERE condition using textbox on form
I'm trying to get a report to limit to the regions/departments that are specific to the ones in a textbox in a form.
I can get them to display in a report by using the .value, however I now matter what I do, I can't get it to display anything if I put it in the IN condition.
Code:
SELECT Rgn_dept, forms!frmReports!txtAllRegions.value
FROM MyTable
WHERE Rgn_dept IN (forms!frmReports!txtAllRegions.value)
I have even tried
Code:
SELECT Rgn_dept, forms!frmReports!txtAllRegions.value
FROM MyTable
WHERE Rgn_dept IN (forms!frmReports!txtAllRegions)
Please RATE posts, click the RATE button to the left under the Users Name.
Once your thread has been answered, Please use the Thread Tools and select RESOLVED so everyone knows your question has been answered.
"As I look past the light, I see the world I wished tonight, never the less, sleep has come, and death shall soon follow..." © 1998 Jeremy J Swartwood
-
Apr 9th, 2010, 02:51 AM
#2
Re: SQL IN WHERE condition using textbox on form
Try this
Code:
SELECT Rgn_dept, Trim(forms!frmReports!txtAllRegions.value)
FROM MyTable
WHERE Rgn_dept IN (Trim(forms!frmReports!txtAllRegions.value))
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Apr 9th, 2010, 12:32 PM
#3
Thread Starter
Fanatic Member
Re: SQL IN WHERE condition using textbox on form
Koolsid,
Nope that didn't work either.
Its like the IN command is having issues with the fact the items to look at, the comma seperated list of values, is in a textbox on a form, instead of hard coded values.
If I replace the forms!frmReports!txtAllRegions.value with the comma seperated values 14,19,5,18,4,3,17,23,28,24,16,15,6,7,2,8,9,1,11,22,21,26,12,25,20,10,27 everything works fine.
This list above I copied directly from the textbox.
I guess I'm going to have to go with an exists query. I'm trying to limit the regions/departments that the managers can see, to the ones they manage.
I don't want to just throw it in as another joined table, because admins have only 1 region they belong to, but there level is Admin, which automatically gives them access to all regions.
I'm thinking about just doing a where
Code:
EXISTS (
SELECT tblManagers.Rgn_Dept
FROM tblManagers
WHERE MyTable.Rgn_Dept = tblManagers.Rgn_Dept
AND tblManagers.EmployeeID = forms!frmReports!txtEmployeeID)
I wanted to avoid this method, as I'm sure it requires more processing/data to be sent accross the network.
Please RATE posts, click the RATE button to the left under the Users Name.
Once your thread has been answered, Please use the Thread Tools and select RESOLVED so everyone knows your question has been answered.
"As I look past the light, I see the world I wished tonight, never the less, sleep has come, and death shall soon follow..." © 1998 Jeremy J Swartwood
-
Apr 9th, 2010, 12:54 PM
#4
Re: SQL IN WHERE condition using textbox on form
 Originally Posted by rack
Its like the IN command is having issues with the fact the items to look at, the comma seperated list of values, is in a textbox on a form, instead of hard coded values.
That is entirely expected... because the textbox contains a single value (a string containing multiple numbers and commas), whereas what you type in to the query is multiple number values separated by commas.
I'm not aware of a way to write a query that would treat the single value as multiple for an IN list, and suspect the best way for a query would be a table to store records for each of the values.
-
Apr 9th, 2010, 02:18 PM
#5
Thread Starter
Fanatic Member
Re: SQL IN WHERE condition using textbox on form
[QUOTE=si_the_geek;3774030]That is entirely expected... because the textbox contains a single value (a string containing multiple numbers and commas), whereas what you type in to the query is multiple number values separated by commas.
QUOTE]
Ah so its looking to match "14,19,5,18,4,3,17,23,28,24,16,15,6,7,2,8,9,1,11,22,21,26,12,25,20,10,27" with each Rgn_Dept field value. That would make sense for it not showing any records then.
The Exists query in the WHERE condition works. I don't create tables on the fly in any of my code/database(s), or that would be a good idea Si_the_geek. I"ll use the Exists where condition instead for now.
Thank you both for the input, and Si_the_Geek for the explanation, that helps a lot knowing what it is trying to do.
Please RATE posts, click the RATE button to the left under the Users Name.
Once your thread has been answered, Please use the Thread Tools and select RESOLVED so everyone knows your question has been answered.
"As I look past the light, I see the world I wished tonight, never the less, sleep has come, and death shall soon follow..." © 1998 Jeremy J Swartwood
-
Apr 9th, 2010, 02:31 PM
#6
Re: SQL IN WHERE condition using textbox on form
 Originally Posted by rack
I don't create tables on the fly in any of my code/database(s), or that would be a good idea Si_the_geek.
There are times when it can be useful, but in general within Access it should be avoided.
As you've got something that works, I'd recommend sticking with it.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|