Solved

How to filter using select statement with like

Posted on 1998-05-20
6
275 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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…
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…

737 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