473,324 Members | 2,370 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,324 software developers and data experts.

LIKE SQL statement

I have tried every combintion I can think of to get a VB5 recordset
SQL query using the LIKE keyword to work recognizing the '*' wildcard
character, but with no success. Why doesn't the LIKE keyword work with
VB5 using ADO or DAO?

Dim T$

T$ = App.Path & "\MyAccess2000DB.mdb"
T$ = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & T$
ConnectStr = T$

With myConnect
On Error Resume Next
.ConnectionString = ConnectStr
.ConnectionTimeout = 10
.Open
On Error GoTo 0
End With

Set CorpRS = New ADODB.Recordset
CorpRS.ActiveConnection = myConnect
CorpRS.CursorType = adOpenDynamic
CorpRS.LockType = adLockOptimistic

field$ = "Symbol"
term$ = "IBM"

'this works but I can't get wildcards to work
sql$ = "Select * from Corporations WHERE " & field$ & " Like '" &
term$ & "'"

CorpRS.Open sql$

I cannot equate term$ to anything and get the query to recognize
wildcards.
For example, if term$ = "*M*", I want the query to return MSFT, MMM,
MCD, etc.

Any ideas?

Thank you.

---
Allen

Jul 17 '05 #1
1 7932
Found the answer:

In ADO, the wild card character is "%", not "*".
Sheeesh!

---
Allen
"Woof-Woof" <ot*********@cox.net> wrote in message
news:ktsFc.35326$6r1.33788@fed1read06...
I have tried every combintion I can think of to get a VB5 recordset
SQL query using the LIKE keyword to work recognizing the '*' wildcard character, but with no success. Why doesn't the LIKE keyword work with VB5 using ADO or DAO?

Dim T$

T$ = App.Path & "\MyAccess2000DB.mdb"
T$ = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & T$
ConnectStr = T$

With myConnect
On Error Resume Next
.ConnectionString = ConnectStr
.ConnectionTimeout = 10
.Open
On Error GoTo 0
End With

Set CorpRS = New ADODB.Recordset
CorpRS.ActiveConnection = myConnect
CorpRS.CursorType = adOpenDynamic
CorpRS.LockType = adLockOptimistic

field$ = "Symbol"
term$ = "IBM"

'this works but I can't get wildcards to work
sql$ = "Select * from Corporations WHERE " & field$ & " Like '" & term$ & "'"

CorpRS.Open sql$

I cannot equate term$ to anything and get the query to recognize
wildcards.
For example, if term$ = "*M*", I want the query to return MSFT, MMM,
MCD, etc.

Any ideas?

Thank you.

---
Allen

Jul 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: David Lozzi | last post by:
OK, I know how to use to pull up all records that contains the keyword, but what about not containing the keyword? I've tried NOT LIKE but i get Arguments are of the wrong type, are out of...
1
by: ITHELP | last post by:
I am using a form to find some data from a table. In the table are fields such as Client name, job number, and job description. I built a query using a SQL statement through the 'Record source' for...
4
by: Tom Walker | last post by:
I cannot get the WHERE statement to work correctly unless I use a literal with the LIKE. I want to use a working storage data name so that I can vary the WHERE statement. Example that works: ...
18
by: Bill Smith | last post by:
The initial row is inserted with the colPartNum column containing a valid LIKE pattern, such as (without the single quotes) 'AB%DE'. I want to update the column value with the results of a query...
9
by: Peter | last post by:
My problem is the last bit of coding below, the like statement does not work. what I have is a product options field and in it is stored characters i.e. "avcy" etc what the query does is...
5
by: Andreas Müller | last post by:
Hi, I was wondering, if there is something similar in VB.NET like the using statement in C#. What it does is to automatically call Dispose on the object decrared with in the statement when the...
26
by: brenocon | last post by:
Hi all -- Compared to the Python I know and love, Ruby isn't quite the same. However, it has at least one terrific feature: "blocks". Whereas in Python a "block" is just several lines of...
3
by: Clearview | last post by:
This is my first post to the forum and hoping I can get help as I have spent a way too much time on this problem, and thinking it is probably something really simple to resolve. I am using Access...
6
by: vasudevram | last post by:
Hi group, Question: Do eval() and exec not accept a function definition? (like 'def foo: pass) ? I wrote a function to generate other functions using something like eval("def foo: ....") but...
2
sharijl
by: sharijl | last post by:
Can someone explain the correct way to query SQL with a like or statement. so I want to SELECT * from table where column like 'Something%' or like 'somethingelse%' I tried it and get syntax...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.