TomGuy
02-22-2002, 08:11 AM
How can I autocomplete a text box like in IE? If anyone knows how to do this please let me know. Every thread I've seen on this seems to lead no where.
Thanks,
Tom
Thanks,
Tom
Autocomplete textboxTomGuy 02-22-2002, 08:11 AM How can I autocomplete a text box like in IE? If anyone knows how to do this please let me know. Every thread I've seen on this seems to lead no where. Thanks, Tom Flyguy 02-22-2002, 08:15 AM Call MakeAutoComplete(Text1) Private Declare Function SHAutoComplete _ Lib "Shlwapi.dll" _ (ByVal hwndEdit As Long, _ ByVal dwFlags As Long) As Long Private Const SHACF_DEFAULT As Long = &H0 Public Sub MakeAutoComplete(ByRef TextB As TextBox) Call SHAutoComplete(TextB.hWnd, SHACF_DEFAULT) End Sub Tip by Karl Moore TomGuy 02-22-2002, 08:32 AM Thanks, but where does it pull the autocomplete words from? I'd like to pull it from a list in an Access database. Is this possible using this function, or would I need something else? Thanks, Tom Flyguy 02-22-2002, 08:51 AM I've no idea! If you want to use your own database you have to write your own function I think. Will try the code I pasted... Tried the code, It has no use at all, unless you want to use the textbox for an URL when making your own browser :D IanPatton 02-22-2002, 08:53 AM This searches a list box that is connected to a DB Code: ------------------------------------------------------------------------------------ Private Sub txtFind_Change() Dim entryNum As Long Dim txtToFind As String txtToFind = txtFind.Text entryNum = sendMessageByString(List1.hwnd, _ LB_SELECTSTRING, 0, txtToFind) End Sub ------------------------------------------------------------------------------------ As the user types in the box the word auto completes Phoebe 02-22-2002, 08:55 AM It sounds like you would be interested in using datacombo or datalist. DBCombo has a .matchentry property You need to refer Microsoft Data Bound List Control to have them in your toolbox. It took me a while to figure out everything at first, but DBCombo works for me. TomGuy 02-22-2002, 08:56 AM Thanks, but what is "sendMessageByString" and where do yo define it? Thanks, Tom IanPatton 02-22-2002, 09:02 AM Sorry forgot about that Declare it in a general procedure like this. Code: -------------------------------------------------------------------------------- Option Explicit Public Declare Function sendMessageByString& Lib "user32" _ Alias "SendMessageA" (ByVal hwnd As Long, _ ByVal wMsg As Long, ByVal wParam As Long, _ ByVal lParam As String) Public Const LB_SELECTSTRING = &H18C Public gFindString As String Public Const gDataBaseName = "C:\My Documents\SVSM Look Up\SVSM" ----------------------------------------------------------------------------------- hope this helps Squirm 02-22-2002, 09:06 AM Most users will be more accustomed to it being defined as SendMessage like so: Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long TomGuy 02-22-2002, 09:15 AM OK, I gues I'm still not getting this. How is it connected to my database? Thanks, Tom IanPatton 02-22-2002, 09:27 AM The project in this case is a DAO control but you could also use ADO. I've attached the project, unzip to my docs if you want to take a look TomGuy 02-22-2002, 09:38 AM I ran your project and got an error that says: "Couldn't find installable ISAM".....any ideas? IanPatton 02-22-2002, 09:57 AM No it works fine here have a look and see if the Microsoft DAO 3.51 object library is referenced. If it isn't that it my be a mdac problem. TomGuy 02-22-2002, 10:05 AM Yes it's referenced. Basically what I want to know is this: Are the words from your database populating the listbox "List1"? If so, could I just put some words in the listbox to test it? If not, what is it doing? I know I'm close, I just need a little push... Thanks, Tom IanPatton 02-22-2002, 10:11 AM Yes the database is populating the list box and as you type in the text box the list box searches and autocompletes to the nearest text in the db (matched to your typed selection) TomGuy 02-22-2002, 10:21 AM ...the list box searches and autocompletes to the nearest text in the db...It autocompletes the textbox right? When I typed a few entries into the list box to test it, the text box did not try to auto complete......the way it does in Internet Explorer when you type www.visu, the rest of the word that matches it in the list is highlighted; albasicforum.com That's what I want to happen....is that what should be happening? Thanks, Tom Squirm 02-22-2002, 10:32 AM The type in Internet Explorer is a combo box. I have seen this problem addressed quite a few times here on the forums. Do a search...... ;) IanPatton 02-22-2002, 10:35 AM It's not the text box but the list box that autocompletes. Squirm is right what you probably need is a combo box so that you can type directly into it. Sorry Phoebe 02-22-2002, 12:20 PM Rrr, ... may I suggest (again) ... DBCombo? You can link a column of a database table to it and it would auto complete according to the content of the column Why didn't anybody bother to consider my earlier posting? :( TomGuy 02-22-2002, 12:35 PM My bad.....If you'd like, I'll give you my address so that you can come and beat me a little. I mean the way it autocompletes in Excel. I was thinking IE but remembering how it works in Excel....and then confusing them (long day, long week)... If you type something in the first cell of Excel (A1) like "My string" and then move down to the cell below it (A2), and type the letter "M", the rest of the word will show up highlighted. How could this be done. Again, sorry 'bout the confusion. Thanks, Tom Phoebe 02-22-2002, 01:22 PM Wow, thanks for the offer, but I'll pass. Regarding the feature that you want to have, it can be done, but you have to be clear on what you need first: 1. Where do YOU want to store the 'words' (database, textfiles, or etc) 2. Like Squirm pointed out, the IE address thingie is a combo box, is that exactly what you want? Your most recent posting mentioned Excel (Excel is a grid-like creature) When using DBCombo, minimal coding is necessary because thanks to the .matchentry property. All you would do is bind DBCombo to the column that contains the values. There are a couple of situations why DBCombo will not work. But we can still have autocomplete feature with a combo box or even a textbox. Here is an example ------------- Load the preset keywords in a listbox (can also be an array). In the change_event of the textbox, write codes that would compare its content to the list or array. Something like this: Private Sub Text1_Change() Dim intCounter As Integer 'Generic counter for calculation Dim intNumOfChar As Integer 'The number of character typed in If Text1.Text <> "" Then intNumOfChar = Len(Text1.Text) 'Get how many character already typed For intCounter = 0 To List1.ListCount - 1 If UCase(Text1.Text) = UCase(Left(List1.List(intCounter), Len(Text1.Text))) Then Text1.Text = List1.List(intCounter) 'The 2 lines below are intended to highlight the extra strings added (so user can retype over it) Text1.SelStart = intNumOfChar Text1.SelLength = Len(Text1.Text) End If Next End If End Sub -- A couple of options there, I hope that would help. Of course, you have to consider how many strings you are going to store and stuff. TomGuy 02-22-2002, 02:21 PM SSSWWWWWEEEEEEETTTTTT!!!! That's exactly what I wanted. So simple, so sweet! Thanks a heap, Tom |
EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum