Results 1 to 10 of 10

Thread: [RESOLVED] PLEASE HELP.. I have problem on using the LIKE on SELECT... in vb program 6.0

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2006
    Posts
    121

    Resolved [RESOLVED] PLEASE HELP.. I have problem on using the LIKE on SELECT... in vb program 6.0

    I am having hard time to this, when i use the...
    "select * from personalinfo where
    personalinfo.lastname = " & "'" & txtlastname.Text & "'"

    The above work to what i am expected... however, when i am using the....

    "select * from personalinfo where
    personalinfo.lastname LIKE " & "'" & txtlastname.Text & "'"

    This does not work as what i want which the user can type just the first 3 letters or four or etc.... of the lastname... I am using the access database as my backend...

    My input includes the asterist the textbox like "SACHEZ", i put "SANC*", but this is not recognized just want to know why and is there a bug on using LIKE word in VB 6.0?

    PLEASE HELP... the code is there bellow

    =============================================


    Option Explicit

    Dim Dbhrd As Connection
    Dim RsQuery As Recordset

    Private Sub Form_Load()
    Set Dbhrd = New Connection
    Set RsQuery = New Recordset

    Dbhrd.CursorLocation = adUseServer
    Dbhrd.Open "PROVIDER=microsoft.jet.oledb.4.0;" & _
    "Data Source=r:\hrddatafile.mdb;" & _
    "Persist Security Info=False;" & _
    "Jet OLEDBatabase Password=" & vpassadmin
    End Sub

    Private Sub RSQueryOpen()
    RsQuery.Source = "SELECT * From personalinfo " & _
    "WHERE personalinfo!lastname LIKE " & _
    "'" & txtlastname.Text & "'"
    RsQuery.ActiveConnection = Dbhrd
    RsQuery.CursorLocation = adUseClient
    RsQuery.LockType = adLockPessimistic
    RsQuery.CursorType = adOpenKeyset
    RsQuery.Open
    End Sub


    'THANK YOU

  2. #2
    PowerPoster lintz's Avatar
    Join Date
    Mar 2003
    Location
    The 19th Hole
    Posts
    2,697

    Re: PLEASE HELP.. I have problem on using the LIKE on SELECT... in vb program 6.0

    Try this....
    VB Code:
    1. select * from personalinfo where lastname LIKE '" & txtlastname.Text & "*'"

  3. #3
    Addicted Member o0yuna0o's Avatar
    Join Date
    Mar 2006
    Posts
    172

    Re: PLEASE HELP.. I have problem on using the LIKE on SELECT... in vb program 6.0

    if you want to query the first three or sequence of letters ONLY.

    you should do this:

    "SELECT * From personalinfo " & _
    "WHERE personalinfo!lastname LIKE " & _
    "'" & txtlastname.Text & "%'"
    Last edited by o0yuna0o; Aug 10th, 2006 at 07:45 PM.

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Aug 2006
    Posts
    121

    Re: PLEASE HELP.. I have problem on using the LIKE on SELECT... in vb program 6.0

    can i ask somethin..? what's the difference between including on textbox input and the select * from personalinfo where lastname LIKE '" & txtlastname.Text & "*'"

    Is there a difference on it?

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Aug 2006
    Posts
    121

    Re: PLEASE HELP.. I have problem on using the LIKE on SELECT... in vb program 6.0

    no? it is not just a three letter.. the input will depend on the users input.. that was just my example...

  6. #6
    Addicted Member o0yuna0o's Avatar
    Join Date
    Mar 2006
    Posts
    172

    Re: PLEASE HELP.. I have problem on using the LIKE on SELECT... in vb program 6.0

    Quote Originally Posted by enricoisles
    can i ask somethin..? what's the difference between including on textbox input and the select * from personalinfo where lastname LIKE '" & txtlastname.Text & "*'"

    Is there a difference on it?
    I see... try the percent sign instead of "*". The wildcard in query is "%"

    If you want you can do this code replace(text1.text,"*", "%")



  7. #7
    Addicted Member o0yuna0o's Avatar
    Join Date
    Mar 2006
    Posts
    172

    Re: PLEASE HELP.. I have problem on using the LIKE on SELECT... in vb program 6.0

    VB Code:
    1. "SELECT * From personalinfo " & _
    2. "WHERE personalinfo!lastname LIKE " & _
    3. "'" & replace(txtlastname.Text,"*","%") & "'"

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Aug 2006
    Posts
    121

    Re: PLEASE HELP.. I have problem on using the LIKE on SELECT... in vb program 6.0

    its works bro... thanks... i used the % sign instead of * asterisk... thankss... hahaha... you guys are much reliable than my books hahaha.... thanksss... hahaha..

  9. #9
    Addicted Member o0yuna0o's Avatar
    Join Date
    Mar 2006
    Posts
    172

    Re: PLEASE HELP.. I have problem on using the LIKE on SELECT... in vb program 6.0

    Quote Originally Posted by enricoisles
    its works bro... thanks... i used the % sign instead of * asterisk... thankss... hahaha... you guys are much reliable than my books hahaha.... thanksss... hahaha..

    no problem...

    Mark this thread resolved if your problem is answered

  10. #10
    PowerPoster lintz's Avatar
    Join Date
    Mar 2003
    Location
    The 19th Hole
    Posts
    2,697

    Re: [RESOLVED] PLEASE HELP.. I have problem on using the LIKE on SELECT... in vb program 6.0

    Glad we could help

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