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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to bind the textbox with listbox

Status
Not open for further replies.

Vincentan

MIS
Aug 21, 2002
52
0
0
MY
Hi all expert!

I'm using adodb for my sql database, I have a text box where try to code it as search fields, when the user key-in the textbox it will auto display the listbox which attache as follow and it will search by every single character.

the example code are:

Private Sub txtFCode_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case 97 To 122: KeyAscii = KeyAscii - 32
End Select
Char = Chr(KeyAscii)
Set RSSQL = New ADODB.Recordset
RSSQL.Open "Select * from Table_FILE where itemcode like '" & Char & "*'", , adOpenDynamic, adLockOptimistic
Set DataGrid.DataSource = RSSQL
DataGrid.HoldFields
DDataGrid.Refresh
MsgBox Char
End Sub

but it return error when i run it.

 
One point, the way you are currently trying to do it would be very difficult for the user to use. e.g. If they typed in CAT in the Textbox, your app would try and find all of the C's, then all of the A's (and not display the C's) and then all of the T's.
A minor point I know but you could change
Code:
Char = Chr(KeyAscii)
to
Code:
Char = Char & Chr(KeyAscii)
And you never close the recordset before you try and open it again...
Hope this helps

Harleyquinn

---------------------------------
For tsunami relief donations
 
Vincentan,

Look at the thread I just started "Information into Textboxes" which Harleyquinn has been good enough to help me with. It connects to an Access db, populates text boxes with data (first name, surname and address) and also searches the db for a specific surname and populates the combo box with the first names. You can then select the first name from the list and it will insert that information the text boxes.

If I can help you any further, let me know.
 
Thanks for your advise Harley and Tag!

But the problem is I woudd like to put in some control or even where it helps to show up the record which using statement LIKE in sql, someting like when user type in C it goes to LIKE "C*" and if CA then come to LIKE "CA*" and etc..

When this state capture it will show all the records which is LIKE "C*" in the listbox, I beleave that this can be done as I saw some one did it and this is very use full which I can make it as class and DLL.

This is just what I want :) do your have some sample?

Thanks

 
I think I know what you mean. The only time I have used the like statement was

Set rs = conn.Execute("SELECT TEST_NAME FROM TESTGUIDE WHERE TEST_NAME= '" & txtText3 & "' or AKA like '%" & txtText3 & "%'")

The % act like wildcard characters. What I think you are trying to do is when someone types in "C" all the "C"s come up but when they type an "A" as well you want the "CA"s to show and if they were to type in a "D" it would find "CAD". Am I right? If I am, sorry I have no idea unfortunately but if I work it out, I'll post back.
 
Vincentan,

If you look at my very first post that describes exactly what you are trying to do.

If you use the Char variable in the LIKE statement (as you already do) the code I gave you to add a value to the existing Char value (the second line of code in the post) would create the search criteria as you want it.

Hope this helps

Harleyquinn

---------------------------------
For tsunami relief donations
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top