473,427 Members | 1,767 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,427 software developers and data experts.

Problem with "WHERE-IN" statement in SQL

40
Hello,

I have an access report with WHERE clause: "WHERE tMonth in (Forms!frmMain!txtMonths)"

when txtMonths = "7" (f.e.) it works just fine, but when I try to execute the code when txtMonths = "7,8" it displays empty report

Any idea what can be wrong?
Sep 3 '07 #1
5 2500
FishVal
2,653 Expert 2GB
Hello,

I have an access report with WHERE clause: "WHERE tMonth in (Forms!frmMain!txtMonths)"

when txtMonths = "7" (f.e.) it works just fine, but when I try to execute the code when txtMonths = "7,8" it displays empty report

Any idea what can be wrong?
Hi, there.

The idea is that "7,8" is being treated as single value, not as list of values.
Try to generate SQL statement in VBA using string concatenation and then either put it to Report.RowSource or QueryDef.SQL of the query the report based on.
Sep 3 '07 #2
Stwange
126 Expert 100+
Hello,

I have an access report with WHERE clause: "WHERE tMonth in (Forms!frmMain!txtMonths)"

when txtMonths = "7" (f.e.) it works just fine, but when I try to execute the code when txtMonths = "7,8" it displays empty report

Any idea what can be wrong?
You could try this instead, it should work I think:

WHERE (Forms!frmMain!txtMonths) LIKE '*tMonth*'

If it doesn't work (I'm not sure if * matches an empty string or not), you might need two ORs, ie. *value*, *value and value*, but I doubt it.

Hope this helps.
Sep 3 '07 #3
saddist
40
The problem is that SQL statement is too long and it places 9 at the end of string and stops adding :/
Besides I can't change recordsource of report. When I try to do that I either get message "can't change row source becouse report is not open" or "u can't change row source when report is open or printing".
I can only change recordsource while in design view, and I dont want user to be is design view...
Sep 3 '07 #4
FishVal
2,653 Expert 2GB
The problem is that SQL statement is too long and it places 9 at the end of string and stops adding :/
Besides I can't change recordsource of report. When I try to do that I either get message "can't change row source becouse report is not open" or "u can't change row source when report is open or printing".
I can only change recordsource while in design view, and I dont want user to be is design view...
Open the report with
Expand|Select|Wrap|Line Numbers
  1. DoCmd.OpenReport WhereCondition:="tMonth IN (" & Forms!frmMain!txtMonths & ")"
  2.  
Sep 3 '07 #5
JConsulting
603 Expert 512MB
Hello,

I have an access report with WHERE clause: "WHERE tMonth in (Forms!frmMain!txtMonths)"

when txtMonths = "7" (f.e.) it works just fine, but when I try to execute the code when txtMonths = "7,8" it displays empty report

Any idea what can be wrong?
It's been my experience that you can't pass a string to an IN() clause. You whould create an OR statement instead.
Sep 3 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: LRW | last post by:
I'm not exactly sure how to even ask the question, and I know my terminology is not good as I'm a SQL beginner, but, here goes. I need to find a way to make an if statement within an array...or,...
6
by: Ron Brennan | last post by:
This is from an application and not an Applet. I believe it goes to stdout but when I do a test and write an abitrary string and then do a search of the hard disk for the string, I can't find...
0
by: Yann GAUTHERON | last post by:
Hi, ID_LOGIN is an integer Can anyone say me if this : WHERE index1=ID_LOGIN OR index2=ID_LOGIN must be slower than those 2 queries :
5
by: Ralf Wahner | last post by:
Dear Masters of XML As I'm new to XML Schema I dare to ask a possibly recurring question: Given an element <elem> with two attributes @a and @b. The attributes are bound by the condition, that...
10
by: joshsackett | last post by:
I am starting an encryption project for my database and I'm performing some tests on decryption speed. A lot of my application queries use a LIKE parameter in the WHERE clause. To keep from...
3
by: bughunter | last post by:
IMHO, statements like this is mistake typically. May be more better made this construction - I said about empty WHERE - invalid? A lot of data will saved... :-) Andy
13
by: andro | last post by:
Hi everybody! I have several tables from which I want to exract the SAME value (along with other referenced data). All the values are in the same column within the tables. How can I achieve...
5
by: davehansen22 | last post by:
Is there a way to generate a MySQL WHERE clause from a search string like this: "(dave OR hansen) php programmer" I would want to use the generated MySQL clause against a "memo" type field. ...
0
by: niklang | last post by:
Hi everybody, First post but i really need some help with this as its driving me mad. I need to format a number to be a currency and when i saw that this was supported already by the...
5
by: John Nagle | last post by:
Does text = unicode(text) make a copy of a Unicode string, or is that essentially a free operation if the input is already Unicode? John Nagle
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.