VB 6.0 Auotfiltering in textbox

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • k4012656
    New Member
    • Aug 2007
    • 11

    #1

    VB 6.0 Auotfiltering in textbox

    HI...Im researching for how to auto filter the text box while im typing inside it (ex. I type A in the VB textbox and all records that have letter A will appear dropdown and as I proceed typing Am all records that have Am will appear dropdown) plzzzzzzzzzzzzz z..... any one can give me some code how to do this in my VB 6.0 project....Im using sql as my database!



    I will be thankful if any one will reply!thnx....
  • hariharanmca
    Top Contributor
    • Dec 2006
    • 1977

    #2
    Originally posted by k4012656
    HI...Im researching for how to auto filter the text box while im typing inside it (ex. I type A in the VB textbox and all records that have letter A will appear dropdown and as I proceed typing Am all records that have Am will appear dropdown) plzzzzzzzzzzzzz z..... any one can give me some code how to do this in my VB 6.0 project....Im using sql as my database!



    I will be thankful if any one will reply!thnx....

    Use the query like

    [CODE=sql]strSql = "Select <Field Names> from <Table Name> where <Search Field> like '" & strSearchText & "%'"[/CODE]

    Comment

    • Killer42
      Recognized Expert Expert
      • Oct 2006
      • 8429

      #3
      Originally posted by k4012656
      ... auto filter the text box while im typing inside it (ex. I type A in the VB textbox and all records that have letter A will appear dropdown and as I proceed typing Am ...
      I'm guessing you must be referring to a listbox or something of that sort? A textbox can only display one thing at a time.

      Comment

      • QVeen72
        Recognized Expert Top Contributor
        • Oct 2006
        • 1445

        #4
        Hi,

        use a ComboBox, It can Act as both TextBox and a ListBox. Write the Code in KeyPresss event, to populate the Combo..

        REgards
        Veena

        Comment

        • hariharanmca
          Top Contributor
          • Dec 2006
          • 1977

          #5
          Combo Box is not good for huge list because that will not automatically show the list and we should add 3 to 30 items (Static Data).

          We have to use programmaticall y adding items in ‘List Box’ or ‘List view’ with ‘Text Box’ combination.

          Comment

          • QVeen72
            Recognized Expert Top Contributor
            • Oct 2006
            • 1445

            #6
            Hi hari,

            what is this " we should add 3 to 30 items (Static Data)"....?
            Why do we need to add Static Data...?

            I always prefer TextBox + ListBox Combination with "Sorted" property of the ListBox =True. Since he said he wants to type, I suggested ComboBox


            REgards
            Veena

            Comment

            • syamas
              New Member
              • Sep 2007
              • 10

              #7
              Originally posted by k4012656
              HI...Im researching for how to auto filter the text box while im typing inside it (ex. I type A in the VB textbox and all records that have letter A will appear dropdown and as I proceed typing Am all records that have Am will appear dropdown) plzzzzzzzzzzzzz z..... any one can give me some code how to do this in my VB 6.0 project....Im using sql as my database!



              I will be thankful if any one will reply!thnx....

              Hey friend
              use a frame named 'framepartdet'
              put MSFlex grid named 'searchgrid' on 'framepartdet' with three columns, fixed rows 2



              [CODE=vb]Private Sub txtcode_Change( ) 'event
              Dim i As Integer
              If rsstock.State = adStateOpen Then rsstock.Close
              Dim ccode As String
              If txtcode.Text = "" Then ' text box value
              framepartdet.Vi sible = False
              Exit Sub
              End If
              ccode = Trim(txtcode.Te xt)
              rsstock.Open "select distinct code,name from table where field like '" & ccode & "%' ", cn, adOpenDynamic, adLockOptimisti c
              If Not rsstock.EOF And Not rsstock.BOF Then
              framepartdet.Vi sible = true
              rsstock.MoveFir st
              i = 0
              searchgrid.Rows = 1
              Do While Not rsstock.EOF
              With searchgrid
              .TextMatrix(i, 0) = i+1
              .TextMatrix(i, 1) = "" & rsstock.Fields( 0)
              .TextMatrix(i, 2) = "" & rsstock.Fields( 1)
              i = i + 1
              .Rows = .Rows + 1
              End With
              rsstock.MoveNex t
              Loop
              Else
              framepartdet.Vi sible = False
              End If
              rsstock.Close
              End Sub[/CODE]

              * link removed *

              Last edited by prometheuzz; Sep 6 '07, 03:15 PM. Reason: * link removed *

              Comment

              • hariharanmca
                Top Contributor
                • Dec 2006
                • 1977

                #8
                Originally posted by QVeen72
                Hi hari,

                what is this " we should add 3 to 30 items (Static Data)"....?
                Why do we need to add Static Data...?

                I always prefer TextBox + ListBox Combination with "Sorted" property of the ListBox =True. Since he said he wants to type, I sujjested ComboBox


                REgards
                Veena
                Originally posted by hariharanmca
                we should add 3 to 30 items (Static Data)"....?
                That is not exact count (that is approximate).
                Static Data - I mean which will change the list index during key press or key up event.

                Comment

                • k4012656
                  New Member
                  • Aug 2007
                  • 11

                  #9
                  thanks!for your reply but i can't get it...can u plz instruct me the step by step method on how can I make a textbox searching in vb6 using my sql database!sorry for being slow...Im only a noob in VB6...

                  Comment

                  • k4012656
                    New Member
                    • Aug 2007
                    • 11

                    #10
                    Originally posted by QVeen72
                    Hi hari,

                    what is this " we should add 3 to 30 items (Static Data)"....?
                    Why do we need to add Static Data...?

                    I always prefer TextBox + ListBox Combination with "Sorted" property of the ListBox =True. Since he said he wants to type, I suggested ComboBox


                    REgards
                    Veena

                    Hi QVeen72
                    tnx for the response...can you teach me how to use combobox in filtering?ex.wh en I type A all names starting A will appear and if i type Ab all names with Ab appear and the names with the letter A but without b will disappear!how can I do that?

                    Comment

                    • k4012656
                      New Member
                      • Aug 2007
                      • 11

                      #11
                      tnx for the response...can you teach me how to use combobox in filtering?ex.wh en I type A all names starting A will appear and if i type Ab all names with Ab appear and the names with the letter A but without b will disappear!how can I do that?

                      Comment

                      • k4012656
                        New Member
                        • Aug 2007
                        • 11

                        #12
                        Originally posted by syamas
                        Hey friend
                        use a frame named 'framepartdet'
                        put MSFlex grid named 'searchgrid' on 'framepartdet' with three columns, fixed rows 2



                        [CODE=vb]Private Sub txtcode_Change( ) 'event
                        Dim i As Integer
                        If rsstock.State = adStateOpen Then rsstock.Close
                        Dim ccode As String
                        If txtcode.Text = "" Then ' text box value
                        framepartdet.Vi sible = False
                        Exit Sub
                        End If
                        ccode = Trim(txtcode.Te xt)
                        rsstock.Open "select distinct code,name from table where field like '" & ccode & "%' ", cn, adOpenDynamic, adLockOptimisti c
                        If Not rsstock.EOF And Not rsstock.BOF Then
                        framepartdet.Vi sible = true
                        rsstock.MoveFir st
                        i = 0
                        searchgrid.Rows = 1
                        Do While Not rsstock.EOF
                        With searchgrid
                        .TextMatrix(i, 0) = i+1
                        .TextMatrix(i, 1) = "" & rsstock.Fields( 0)
                        .TextMatrix(i, 2) = "" & rsstock.Fields( 1)
                        i = i + 1
                        .Rows = .Rows + 1
                        End With
                        rsstock.MoveNex t
                        Loop
                        Else
                        framepartdet.Vi sible = False
                        End If
                        rsstock.Close
                        End Sub[/CODE]

                        * link removed *



                        Hi syamas

                        tnx for the response...can you teach me how to use combobox in filtering?ex.wh en I type A all names starting A will appear and if i type Ab all names with Ab appear and the names with the letter A but without b will disappear!how can I do that?

                        Comment

                        Working...