Solved

How to filter using select statement with like

Posted on 1998-05-20
6
273 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
Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…

810 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