PDA

Click to See Complete Forum and Search --> : Here's an easy one


hyme
Jul 10th, 2000, 10:38 AM
When using a text field with a where statement I get "Invalid Column name" WHY?

SQL = "SELECT * FROM Employees where LastName = KING"
rs.Open SQL, dcnNWind, adOpenForwardOnly, adLockReadOnly

Using a number field everything is fine!

SQL = "SELECT * FROM Employees where Employee_ID = 7"
rs.Open SQL, dcnNWind, adOpenForwardOnly, adLockReadOnly


Thanx

hyme
Jul 10th, 2000, 10:43 AM
Using this works

strTest = "King"
SQL = "SELECT * FROM Employees where LastName ='" & strTest & " '"
rs.Open SQL, dcnNWind, adOpenForwardOnly, adLockReadOnly

Clunietp
Jul 10th, 2000, 11:18 AM
you weren't putting single quotes around your criteria:

this
SQL = "SELECT * FROM Employees where LastName = KING"


should have been this
SQL = "SELECT * FROM Employees where LastName = 'KING'"


You properly did that in your second reply, but you might want to lose the space at the end
...'" & strTest & " '"

should be
...'" & strTest & "'"