0

im a complete newbie in visual basic and im currently working on my first project which is the book borrowing system. the project is almost done except with this error.

Syntax error(missing operator) in query expression 'Title like %Mathew Henry's Commentary:GEnesis to Revelation%"

3
Contributors
7
Replies
22
Views
2 Years
Discussion Span
Last Post by lyca
0

Here is the complete query of the error.
I have a combobox, a txtbox namely txtsearch and a datalistfield in which all the titles of the book will appear.

Private Sub txtsearchbook_Change()

If cmbsearchbook.Text <> "" Then
adobooksearch.RecordSource = "SELECT * from tblbooks where " & cmbsearchbook & " like '%" & txtsearchbook.Text & "%'"
adobooksearch.Refresh
Else
adobooksearch.RecordSource = "SELECT * from tblbooks" 'where Author like '%" & "#" & "%'"
adobooksearch.Refresh
End If
End Sub

Edited by lyca

0

HERE:

adobooksearch.Refresh

Edited by lyca

1

Hi

It looks like your WHERE criteria contains a value with an apostraphe so your SQL statement is breaking as the criteria itself needs to be enclosed within apostraphes.

You can either use parameterised queries or escape your search criteria. For example "SELECT * from tblbooks where " & cmbsearchbook & " like '%" & Replace(txtsearchbook.Text, "'", "''") & "%'". Note how the replace function has been used to take one apostraphe and replace it with two, thus escaping it.

HTH

0

This is a query

SELECT * FROM tblbooks WHERE author LIKE 'Smi%'

This is not a query

adobooksearch.Refresh

If you want help debugging the query then post your query.

This question has already been answered. 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.