hi..i got a problem regarding how could populate data from adodb recordset into textbox...when i type the first letter for example of the itemname then automatically the textbox will show different records from the database starting with the first letter i type until i type the next and so forth...pls help me...i dont have an initial code because i try to research but i cant find one and i cnt undrstand...tnk u...

Hi, here's my example on how to do that i'm using Data Control and DBGrid, you type something in a Text Box called Text1 and see the result in DBGrid1.

Private Sub Text1_Change()
Data1.RecordSource = "Select * from Data where No_Id like'" & Text1.Text & "*'"
Data1.Refresh
End Sub

Just convert it to your need.

thnk u so much i really appreciate ur help..i am using the adodb as my recordset..what should i put as my recordsource? is it possible that i dont have to use any listbox or dbgrid to display the result just within the textbox,,,tnx...

i am using the adodb as my recordset..what should i put as my recordsource?

There are different ways to open a recordset.
I usually do the following:

Dim cnAdodb as ADODB.Connection
Dim rst as ADODB.Recordset

Dim strSQL as String 
set cnAdodb = new ADODB.Connection
set rst = new ADODB.Recordset

strSQL = "Select * from Data where No_Id like'" & Text1.Text & "*'"
With cnAdodb
     .Provider = "Microsoft.Jet.OLEDB.4.01" ' Enter the name of your provider
     .Open "C:\MyDatabaseFiles\Mydatafile.mdb", "admin", ""
End With

rst.Open strSQL, cnAdodb, adOpenDynamic, adLockOptimistic


' Close out ADODB objects and reclaim memory set aside for them.
rst.close
cnAdodb.close
set rst = Nothing
set cnAdodb = Nothing

is it possible that i dont have to use any listbox or dbgrid to display the result just within the textbox,,,tnx...

If you set the text property Multiline to True, then you can use the Textbox for more than one line.

tnx...but what i mean s that when i type a name of item automatically the list of item with the same letter to the one i type will automatically appear in the same textbox..is it possible? or i shall put another txtbox to display those items? pls..help me with this...thnk u so much...

  1. Well, you have to load the values for the list you are using a reference somewhere. You have to do this first.
  2. Then you have to use the text entry value to search through the loaded values.
Private Sub LoadArray()
     Dim strArray(25) as string 
     dim i as integer
     rst.MoveFirst
     for i = 0 to 25
          If not rst.EOF then
                strArray(i) = rst.Fields("ListName")
          Else
               exit sub
          End if
          rst.MoveNext
     next i
End Sub

Private Sub ExpandTextBox (ByVal CurrentEntry as String)
     ' Write code here to search through array using the current entry in the text box
     ' Expand the value in the textbox, if you have a search match of the letters to the corresponding amount of letters in the pre-loaded values.
End Sub

yeah i understand what u mean but writing a code to search array..i dnt knw really how...i'm just new in vb6..hope you understand..i know i sounds dependent on you but pls. only ths time...i am very thankful for the time you are spending reading ths post of mine...

Use text input to determine which value or values found in a database recordset to automatically display.

So, you only have what looks like three possible outcomes: (1) one value, (2) multiple values, or (3) no values.

For which outcome do you wish to program? You need to break down the problem into small pieces. And solve the problem piece by piece.

Use the Change Event of the TextBox to select a value to use for your search.

Private Sub Text1_Change()
     Static blnEntered as Boolean 
     if blnEntered then GoTo ResetFlag
     Dim strCurrentText as String
     Dim strDBMatch as string
     Dim intLength as Integer
     strCurrentText = Text1.Text
     intLength = Len(strCurrentText)
     ' Open your recordset
     rst.MoveFirst
     while Not rst.EOF 
         strDBMatch = rst.Fields("MyField") 
         if (len(strDBMatch) >= intLength) then
              if (strCurrentText = left(strDBMatch, intLength)) then
                    Text1.Text = strDBMatch
                    blnEntered = True
              End if
         End if  
     Wend
     Exit Sub
ResetFlag:
     blnEntered = False
End Sub

I haven't tried this. Don't know if it will work. But you see the basic solution. Test the input against the database. Replace the value of the Text box with the value of the field in the recordset. And there's a GoTo. Good Grief!
There are a few problems in the While Loop. But you'll have to fix those. And if you want to search and list Multiple Values. You'll have to figure that out.

I have no idea why a teacher would unleash such a problem on a beginning programmer. He ought to be tanned and hided.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.