Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

populating text box from sql db 1

Status
Not open for further replies.

croakyfrog

Technical User
Dec 4, 2001
51
GB
hi

what i'm trying to do is populate a txt box from a sql db. i don't want the box to have anything in when the user goes to it but i want it to come up with matching results as the user types in the word, ie if they type in w it will come up with a list of "what, where, welly", when they type in wh it will come up with "what and where" and when they type in wha it will just have "what" as the only word in the box.

if anyone understands this dodgy explaination could they explain how this would be done?
 
I would do something like this:

Private Sub txtSearch_Change()
Dim strSearch As String
Dim strSql As String
Dim rsTemp As ADODB.Recordset

strSearch = Trim$(txtSearch.Text)

If strSearch = vbNullString Then
Exit Sub
End If

Set rsTemp = New ADODB.Recordset

strSearch = strSearch & "%"
strSql = "select MyField from MyTable Where MyField Like '" & strSearch & "'" & " Order By MyField"

' Open the recordset using strSql and populate the text box from it. Clear the TextBox first. Add data like this:

txtOut = txtOut & !MyField & vbCrLf
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top