0

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.

1 Answer 1

2

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 & "'"
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.