Solved

How to filter using select statement with like

Posted on 1998-05-20
6
271 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
Comment Utility
Text = "'" & 123 & "'"
Data1.RecordSource = "SELECT * FROM Customer WHERE AccountNo LIKE " & Text & " "
0
 
LVL 7

Expert Comment

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

Expert Comment

by:dochopper
Comment Utility
Also, what database are you using?  If it's access, the %'s from the earlier comment should be astericks.  
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 1

Author Comment

by:dhuang
Comment Utility
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
Comment Utility
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
Comment Utility
NB. If you are using the Access, use the * instead of the % for matching.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

772 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

10 Experts available now in Live!

Get 1:1 Help Now