Results 1 to 3 of 3

Thread: SQL Using LIKE

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 1999
    Location
    Orange, CA USA
    Posts
    1

    Post

    I just want to allow users to find a record based on what they type into a text box on my search form. The data control is on my main form. All attempts to use different combinations of code fail. I am out of Advil & patience!!! Please look at this code and advise.

    RK


    Private Sub cmdOK_Click()

    If Trim(txtFind) = "" Then Exit Sub

    Dim SQL As String
    Dim Name2Find As String

    Name2Find = Trim(txtFind.Text)

    SQL = "SELECT From Customers WHERE LastName Like '%" & txtFind.Text & "%'"

    With frmMain.Data1
    .RecordSource = SQL
    .Refresh
    End With

    Unload Me

    End Sub

  2. #2
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744

    Post

    What Database are you using? Access, SQL Server, Oracle???

    Also, what data control are you using? Is it regular data control or ADO data control??

    If you use Oracle or SQL Server then your SQL statement should be:


    SQL = "SELECT From Customers WHERE LastName Like " & txtFind.Text & "%"


    If you use Access database and a regular Data control then your SQL statement should be:

    SQL = "SELECT From Customers WHERE LastName Like " & txtFind.Text & "*"


    Regards,

    ------------------

    Serge

    Software Developer
    [email protected]
    [email protected]



  3. #3
    Lively Member
    Join Date
    Jan 1999
    Posts
    82

    Post

    Hi,

    Actually, if you are using an Oracle database then your string needs to be surrounded by single quotes, but you also need to specify WHAT you want to select:

    SQL = "SELECT * From Customers WHERE LastName Like '%" & txtFind.Text & "%'"

    HTH,

    Preeti

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