Talal Abdoh
Talal Abdoh

Reputation: 159

Syntax error (missing operator) in query expression on vb6

I have been searching for an answer on Stack Overflow and on Google but found nothing. I am doing this as a school project and can not get my head around it. I'm am working with a Access Database and it will not allow me to search for the last name.

Here is my problem: Syntax error (missing operator) in query expression 'Last Name = '(Namethatwastypedwithoutbrackets)"

And this is my code

Private Sub cmdSearch_Click()
Dim sql As String

Call Conn.Connect
Adodc1.ConnectionString = Conn.connstr


Adodc1.CommandType = adCmdText
Adodc1.ConnectionString = connstr
sql = "Select * from Table1 where Last Name  = '" & txtSearch.Text & "'"
Adodc1.RecordSource = sql

Adodc1.Refresh

End Sub

I really appreciate if anyone can tell me what's wrong since i don't have any idea what the error is.

Upvotes: 0

Views: 1354

Answers (1)

Ken White
Ken White

Reputation: 125688

The error message is telling you that you need brackets around your column name (Last Name) because it has spaces in it.

sql = "Select * from Table1 where [Last Name]  = '" & txtSearch.Text & "'"

Upvotes: 2

Related Questions