473,387 Members | 1,504 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,387 software developers and data experts.

Passing SQL "Like" string from VB code into Query Parameter.

ChaseCox
294 100+
I have a Database Called FalconAnalysis.mdb. The table I am wanting to use is called Generic Material. The Query I want to pass the value into is called Material Query. The field in the query is called Order_Model. I would like to pass the result, "strSize", from the following string of code into the Order_Model field of Material Query, which looks at generic Material Table.
Expand|Select|Wrap|Line Numbers
  1. Private Sub MakeFilter2()
  2.  
  3. strSize = ""
  4.  
  5.     If Nz(chkv2125S, False) Then _
  6.             strSize = strSize & ",'150'"
  7.     If Nz(chkv2125H, False) Then _
  8.             strSize = strSize & ",'151'"
  9.     If Nz(chkv215S, False) Then _
  10.             strSize = strSize & ",'180'"
  11.     If Nz(chkv215H, False) Then _
  12.             strSize = strSize & ",'181'"
  13.     If Nz(chkv2175S, False) Then _
  14.             strSize = strSize & ",'210'"
  15.     If Nz(chkv2175H, False) Then _
  16.             strSize = strSize & ",'211'"
  17.     If Nz(chkv220S, False) Then _
  18.             strSize = strSize & ",'240'"
  19.     If Nz(chkv220H, False) Then _
  20.             strSize = strSize & ",'241'"
  21.     If Nz(chkv225S, False) Then _
  22.             strSize = strSize & ",'300'"
  23.     If Nz(chkv225H, False) Then _
  24.             strSize = strSize & ",'301'"
  25.  
  26.  
  27. End Sub
  28.  
I think it should be a like statment, any thoughts on how to do this?
Feb 6 '07 #1
10 3368
ADezii
8,834 Expert 8TB
I have a Database Called FalconAnalysis.mdb. The table I am wanting to use is called Generic Material. The Query I want to pass the value into is called Material Query. The field in the query is called Order_Model. I would like to pass the result, "strSize", from the following string of code into the Order_Model field of Material Query, which looks at generic Material Table.
Expand|Select|Wrap|Line Numbers
  1. Private Sub MakeFilter2()
  2.  
  3. strSize = ""
  4.  
  5.     If Nz(chkv2125S, False) Then _
  6.             strSize = strSize & ",'150'"
  7.     If Nz(chkv2125H, False) Then _
  8.             strSize = strSize & ",'151'"
  9.     If Nz(chkv215S, False) Then _
  10.             strSize = strSize & ",'180'"
  11.     If Nz(chkv215H, False) Then _
  12.             strSize = strSize & ",'181'"
  13.     If Nz(chkv2175S, False) Then _
  14.             strSize = strSize & ",'210'"
  15.     If Nz(chkv2175H, False) Then _
  16.             strSize = strSize & ",'211'"
  17.     If Nz(chkv220S, False) Then _
  18.             strSize = strSize & ",'240'"
  19.     If Nz(chkv220H, False) Then _
  20.             strSize = strSize & ",'241'"
  21.     If Nz(chkv225S, False) Then _
  22.             strSize = strSize & ",'300'"
  23.     If Nz(chkv225H, False) Then _
  24.             strSize = strSize & ",'301'"
  25.  
  26.  
  27. End Sub
  28.  
I think it should be a like statment, any thoughts on how to do this?
Looks more like the In Construct to me:
strPassSQL = "In(" & strSize & ")"
Feb 6 '07 #2
ChaseCox
294 100+
Looks more like the In Construct to me:
strPassSQL = "In(" & strSize & ")"
Does that go into the query, or the VB code?
Feb 6 '07 #3
Rabbit
12,516 Expert Mod 8TB
Looks more like the In Construct to me:
strPassSQL = "In(" & strSize & ")"
You can't have this as the criteria of a query though. I don't think there's a way to run code which will change the criteria of a query from the query itself.

You'll most likely have to do it through a form.
Feb 6 '07 #4
ChaseCox
294 100+
You can't have this as the criteria of a query though. I don't think there's a way to run code which will change the criteria of a query from the query itself.

You'll most likely have to do it through a form.
I have in the past set this value to a text box, and then past that value into the query. Is this the only way to do it?
Feb 6 '07 #5
Rabbit
12,516 Expert Mod 8TB
As far as I know, yes.
Feb 6 '07 #6
ChaseCox
294 100+
As far as I know, yes.
Thanks for the help Rabbit, much appreciated.
Feb 6 '07 #7
Rabbit
12,516 Expert Mod 8TB
Not a problem. Glad to help.
Feb 6 '07 #8
NeoPa
32,556 Expert Mod 16PB
Looks more like the In Construct to me:
strPassSQL = "In(" & strSize & ")"
Try instead using :
Expand|Select|Wrap|Line Numbers
  1. strPassSQL = "In(" & Mid(strSize,2) & ")"
To lose the first ',' character.
Feb 7 '07 #9
NeoPa
32,556 Expert Mod 16PB
I have in the past set this value to a text box, and then past that value into the query. Is this the only way to do it?
It is also possible to set the SQL property of a QueryDef to match what you want.
Your code would have to be sophisticated enough to amend existing SQL.
Let me know if you're interested and/or want more detailed instructions.
Feb 7 '07 #10
nico5038
3,080 Expert 2GB
Why not create a table with the 150, 151, 180, 181, etc. values in a row and an additional checkbox.
Thus you can let the user check the rows in a datasheet subform and all needed is to join this additional table by the code to this table and add the criteria "True" for the checkbox.

Saves the code and you could use a simple UPDATE query to set/reset the checkbox on the form.

Idea ?

Nic;o)
Feb 7 '07 #11

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

Similar topics

5
by: NK | last post by:
Hi all, Does anyone know of how I can disable case sensitivity for the LIKE function in SQL? Currently the SQL statement looks like: $query = "SELECT * FROM itrader_games WHERE...
11
by: Martin Robins | last post by:
I am trying to parse a string that is similar in form to an OLEDB connection string using regular expressions; in principle it is working, but certain character combinations in the string being...
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...
2
by: Dave Smithz | last post by:
Hello there, Summary: How far can you go with SQL Select queries using like clauses with wildcard characters. Can you apply anything like regular expressions? Full details: On a Intranet...
1
by: S. van Beek | last post by:
Dear reader, How can I filter a numeric field with Like as criteria in a query. To filter a numeric field with <10 as criteria this will com back with the result of those records for which...
4
by: mosscliffe | last post by:
I have been messing with the above all afternoon. I must just be thick I am using an AccessDataSource I have tried modifying the select but I can not find the right syntax to concatenate...
11
by: Bruce Lawrence | last post by:
Ok, I'm baffled... I'm making a query in access 97 between 2 tables. There is a field in both tables called "DWGNO". OPENORD has a record with a DWGNO of "00000012345" DIEDATA has a record...
9
by: Drum2001 | last post by:
Hello All! I am using the following code during an On Click event for a button. It works properly to create a query for a report: Private Sub Command14_Click() If IsNull(Me.Text30) Then ' No...
7
by: MLH | last post by:
If I drop Like "*ABC*" in a QBE grid criteria cell, the records returned include mixed case. Can I force the uppercase limitation in a QBE grid?
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.