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

Recommended Answers

All 4 Replies

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

commented: This thread is over two years old and it should have been closed +0
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.