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"?

9 Years
Discussion Span
Last Post by alamnaryab

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")


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

"Select * from <table> where <field> 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.


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.


replace % with * for ms-access

Votes + Comments
This thread is over two years old and it should have been closed
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.