954,559 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How to using "like" in VB6

Hi all.
I have error with script below :

Dim sql as string
sql = "select * from [table] where [field] like '%" & text1.text & "%'"

how must I write "%" after "like"?

murnibta
Newbie Poster
1 post since Sep 2008
Reputation Points: 10
Solved Threads: 0
 

What is the error message you get? SQL seems ok to me.

%-character is used for pattern matching and it matches any number of characters:

sql = "select * from [table] where [field] like 'VB%'"
matches [field] starting with "VB" (like "VB6 Language"),

sql = "select * from [table] where [field] like '%VB'"
matches [field] ending with "VB" (like "Microsoft's VB"), and

sql = "select * from [table] where [field] like '%VB%'"
matches [field] containing "VB" ("My VB6 Tutorial")

Teme64
Veteran Poster
1,031 posts since Aug 2008
Reputation Points: 218
Solved Threads: 203
 

For MS Access, use * (asteriks) instead of %

"Select * from where like '" & text1.text & "*'"

For other databases, it will depend on the database. Oracle uses "%" (IIRC, not 100% sure) and SQL Server uses a different character.

aparnesh
Junior Poster
194 posts since Jul 2005
Reputation Points: 20
Solved Threads: 10
 
For MS Access, use * (asteriks) instead of %


is correct in Access. However, when you use SQL in VB you use %-character. This is with ADO, in DAO you may had to use *-character, don't remember for sure anymore.

Teme64
Veteran Poster
1,031 posts since Aug 2008
Reputation Points: 218
Solved Threads: 203
 

replace % with * for ms-access

alamnaryab
Newbie Poster
1 post since Jan 2011
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You