Results 1 to 4 of 4

Thread: SQL

  1. #1
    Guest

    SQL

    I'm trying to execute this simple SQL statement and I get this error

    Compile Error
    Expected: Line Number or Label or statement or end of statement

    Here is the sql statement I'm using

    Dim strSQL As String

    strSQL = "Select * From tblCompany"
    "Where cCompName Like '" & cmbCmpName.Text & "'"

    DatComp.RecordSource = strSQL
    DatComp.Refresh

    Not sure if I'm supposed to use the like or not. I left my SQL book at home and I don't work with it every day. So if some can help me out I would appreciate it.

    Thank You
    Ken Devorak

  2. #2
    Member
    Join Date
    Jan 2000
    Posts
    51
    Kenny,

    Put the whole SQL into one line. Otherwise you need to
    strSQL = "Select * From tblCompany"
    strSQL = "Where cCompName Like '" & cmbCmpName.Text & "'"

  3. #3
    Fanatic Member Stevie's Avatar
    Join Date
    Mar 2000
    Location
    London, UK
    Posts
    565

    Talking

    Close but not quite

    Either of the following will work.

    Code:
    strSQL = "Select * From tblCompany " 
    strSQL = strSQL & "Where cCompName Like '" & cmbCmpName.Text & "'"
    or
    Code:
    strSQL = "Select * From tblCompany " & _ 
             "Where cCompName Like '" & cmbCmpName.Text & "'"
    Use LIKE if you are trying to find any matches the same or similar to cmbCmpName.

    Use = if you only want an exact match.

  4. #4
    Frenzied Member
    Join Date
    Aug 1999
    Location
    Santa Clara, Ca , 95058
    Posts
    1,105
    I'd give some thought to imbedding an asterisk in the SQL statement. For example

    strSQL = "Select * From tblCompany " & _
    "Where cCompName Like '" & trim(cmbCmpName.Text) & "*'"

    might be more effective.

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