Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to filter using select statement with like

Posted on 1998-05-20
6
Medium Priority
?
279 Views
Last Modified: 2008-02-01
how can I get this to work in VB
Filterinfo = "%123%" 'match 123
    Data1.RecordSource = "select * from [Customer] where [AccountNo] like '" & filterInfo & "'"
0
Comment
Question by:dhuang
6 Comments
 
LVL 7

Expert Comment

by:kamall
ID: 1456325
Text = "'" & 123 & "'"
Data1.RecordSource = "SELECT * FROM Customer WHERE AccountNo LIKE " & Text & " "
0
 
LVL 7

Expert Comment

by:kamall
ID: 1456326
More clearly:
FilterInfo = "'" & 123 & "'"
Data1.RecordSource = "SELECT * FROM Customer WHERE AccountNo LIKE " & FilterInfo
0
 

Expert Comment

by:dochopper
ID: 1456327
Also, what database are you using?  If it's access, the %'s from the earlier comment should be astericks.  
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 1

Author Comment

by:dhuang
ID: 1456328
Kamall: Sorry, I can't give the points to you.
1) The source code gives error, b'cos of the wrong SQL command.
You need the ' after the LIKE
eg. Just like the one in my example.
0
 
LVL 1

Accepted Solution

by:
terencebeh earned 20 total points
ID: 1456329
Hi dhuang,
Try the following:

dim rs as recordset
set rs = db.openrecordset("select * from [Customer] where [AccountNo] like '%" & filterInfo & "%'" , dbopensnapshot, dbsqlpassthrough)
set data1.recordset = rs

(db is your database)
0
 
LVL 1

Author Comment

by:dhuang
ID: 1456330
NB. If you are using the Access, use the * instead of the % for matching.
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

963 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question