473,791 Members | 3,015 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

ChaseCox
294 Contributor
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 3402
ADezii
8,834 Recognized Expert Expert
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 Contributor
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 Recognized Expert Moderator MVP
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 Contributor
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 Recognized Expert Moderator MVP
As far as I know, yes.
Feb 6 '07 #6
ChaseCox
294 Contributor
As far as I know, yes.
Thanks for the help Rabbit, much appreciated.
Feb 6 '07 #7
Rabbit
12,516 Recognized Expert Moderator MVP
Not a problem. Glad to help.
Feb 6 '07 #8
NeoPa
32,579 Recognized Expert Moderator MVP
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,579 Recognized Expert Moderator MVP
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

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

Similar topics

5
48335
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 console='$console' AND genre='$genre' AND title LIKE '%$title%' ";
11
3921
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 parsed can completely wreck it. The string I am trying to parse is as follows: commandText=insert into (Text) values (@message + N': ' + @category);commandType=StoredProcedure; message=@message; category=@category I am looking to retrive name value...
10
7596
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 changing my application I am performing all the work on the back-end; creating views, triggers and UDFs to encrypt/decrypt the data. A problem has arisen around the LIKE parameter, though. Currently: SELECT SSN, FNAME, LNAME FROM USERS WHERE LNAME...
2
13363
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 website, I request a code from a user which is then compared with a code in an ADO access database.
1
3391
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 the value is smaller as teen. But in case this value is variable and you prefer to work with "Like
4
1956
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 the LIKE part of the test by surrounding my textbox field value with a leading and closing %.
11
6409
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 with a DWGNO of "12345" I'm not doing this with VBA right now. I'm doing it through the query gui.
9
2448
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 criteria here - so ignore Else strWhere = strWhere & ",'" & Me.Text30.Value & "'"
7
2447
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
9515
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10427
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10207
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10155
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9995
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9029
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
4110
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3718
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2916
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.