Results 1 to 3 of 3

Thread: Here's an easy one

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2000
    Posts
    148
    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

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    May 2000
    Posts
    148
    Using this works

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

  3. #3
    Guru Clunietp's Avatar
    Join Date
    Oct 1999
    Location
    USA
    Posts
    1,844
    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 & "'"


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width