Solved

How to filter using select statement with like

Posted on 1998-05-20
6
272 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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 10 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

911 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now