Results 1 to 9 of 9

Thread: like and wild card use in access 2003 and select statement in vb6

  1. #1
    Member
    Join Date
    Aug 12
    Posts
    44

    like and wild card use in access 2003 and select statement in vb6

    Hai Every body

    I am using Ms Access 2003 and Vb6
    Table name is : accgeneral
    field name is : Author
    Text box name : Text1
    Listview1 is the name of the Listview control


    '*b*' is working in Access query

    But it is not working as Sql Select statement like below:

    Code:
    rs.Open "Select * from accgeneral where Author like '*" & Text1.Text & "*'", db, 3, 3
    is not working, it simply clear the listview control in run mode, it is not giving any errors, but not working.

    My requirement is find the character where in the name of the author

    above line code is working in access query created from the table accgeneral


    The below code is working well.

    Code:
    Private Sub txtsearch_Change()
    ListView1.ListItems.Clear
    Dim list As ListItem
    Dim x As Integer
    connectDB
    rs.Open "Select * from accgeneral where AccNo like '" & txtsearch.Text & "%'", db, 3, 3
    Do Until rs.EOF
    Set list = ListView1.ListItems.add(, , rs(0))
    For x = 1 To 12
        If Not IsNull(rs(x)) Then
            list.SubItems(x) = rs(x)
        End If
    Next x
    rs.MoveNext
    Loop
    Set rs = Nothing
    db.Close: Set db = Nothing
    End Sub
    Thanks in advance

  2. #2
    PowerPoster
    Join Date
    Feb 12
    Location
    West Virginia
    Posts
    4,978

    Re: like and wild card use in access 2003 and select statement in vb6

    So what is the question?

  3. #3
    PowerPoster techgnome's Avatar
    Join Date
    May 02
    Posts
    21,794

    Re: like and wild card use in access 2003 and select statement in vb6

    Wrong wildcard... ADO recognizes the % as the wildcard... not * ... adjust code as necessary.

    that's why this does work:
    accgeneral where AccNo like '" & txtsearch.Text & "%'"

    and this doesn't:
    Author like '*" & Text1.Text & "*'"



    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.-I also subscribe to all threads I participate, so there's no need to pm when there's an update.*
    *Proof positive that searching the forums does work: View Thread *
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *
    * Use Offensive Programming, not Defensive Programming. * On Error Resume Next is error ignoring, not error handling(tm).
    "There is a major problem with your code, and VB wants to tell you what it is.. but you have decided to put your fingers in your ears and shout 'I'm not listening!'" - si_the_geek on using OERN

  4. #4
    Member
    Join Date
    Aug 12
    Posts
    44

    Re: like and wild card use in access 2003 and select statement in vb6

    Mr.tg
    Thanks for your responce

    the query '*b*' is tested on the table accgeneral in query design mode in access, 2003. working well.

    instead of b a Text box is used to pass the string on the form

    my requirement is the above query have to be write in code as a select statement. I wrote the line of code below:
    Code:
    rs.open"select*from accgeneral Author like '*" & Text1.Text & "*'",db,3,3
    is not working when i run the program. in run mode simply it clear the listview1 control.

    Hope your response

    Thanks

  5. #5
    Hyperactive Member
    Join Date
    Jun 12
    Location
    I'm living in VBForum bcz its members deserve respect and appreciation
    Posts
    318

    Re: like and wild card use in access 2003 and select statement in vb6

    Try the code below hope it's working.
    Code:
    rs.open "SELECT * FROM [accgeneral] Where [Author] LIKE '%" & Trim(Text1) & "%'", db, 3, 3

  6. #6
    Hyperactive Member
    Join Date
    Jun 12
    Location
    I'm living in VBForum bcz its members deserve respect and appreciation
    Posts
    318

    Re: like and wild card use in access 2003 and select statement in vb6

    Duplicate post. Sorry

  7. #7
    Member
    Join Date
    Aug 12
    Posts
    44

    Resolved Re: like and wild card use in access 2003 and select statement in vb6

    Thanks all who respond to this thread

    I modify the line of code as below:

    Code:
    rs.open "select*from accgeneral where Author like '%"& Text1.Text &"%'",db,3,3
    now working as per expectations

    Thanks once again

  8. #8
    PowerPoster
    Join Date
    Feb 06
    Posts
    8,685

    Re: like and wild card use in access 2003 and select statement in vb6

    Note that this isn't ADO, which doesn't know anything about SQL at all.

    It's the Jet 4.0 database engine, which uses a later version of SQL syntax when accessed via the OLEDB Provider you'd normally use when using ADO as your data access library.

    See the article Fundamental Microsoft Jet SQL for Access 2000 in the MSDN Library documentation that comes with VB6.

  9. #9
    PowerPoster techgnome's Avatar
    Join Date
    May 02
    Posts
    21,794

    Re: like and wild card use in access 2003 and select statement in vb6

    Quote Originally Posted by deekshitulu View Post
    Thanks all who respond to this thread

    I modify the line of code as below:

    Code:
    rs.open "select*from accgeneral where Author like '%"& Text1.Text &"%'",db,3,3
    now working as per expectations

    Thanks once again
    I'm sorry... isn't that what I said to do in the first place? I'm sorry I didn't just copy your code and fix it for you directly... how stupid and lazy of me.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.-I also subscribe to all threads I participate, so there's no need to pm when there's an update.*
    *Proof positive that searching the forums does work: View Thread *
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *
    * Use Offensive Programming, not Defensive Programming. * On Error Resume Next is error ignoring, not error handling(tm).
    "There is a major problem with your code, and VB wants to tell you what it is.. but you have decided to put your fingers in your ears and shout 'I'm not listening!'" - si_the_geek on using OERN

Posting Permissions

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