Combo Box Autocomplete problem
hi!
can someone help me how to convert this code to public function... this code works but the problem is i have to copy it in every combo box command. here's the code
VB Code:
Option Explicit
Dim InChangeMode As Boolean
Dim BackSpacePressed As Boolean
Private Sub Combo1_Change()
On Error Resume Next
Dim idx As Integer
Dim SelFrom As Integer
If InChangeMode Then Exit Sub
If BackSpacePressed Then
BackSpacePressed = False
Exit Sub
End If
With Combo1
If Trim(.Text) = "" Then Exit Sub
If .ListCount < 0 Then Exit Sub
InChangeMode = True
For idx = 0 To .ListCount
If UCase(.Text) = UCase(Left(.list(idx), Len(.Text))) Then Exit For
'' If your data in Combox is sorted than add the next line
' If UCase(.Text) < UCase(Left(.List(idx), Len(.Text))) Then GoTo EndOfProcess
Next idx
If idx < .ListCount Then
SelFrom = Len(.Text)
.ListIndex = idx
.SelStart = SelFrom
.SelLength = Len(.Text) - SelFrom
End If
End With
EndOfProcess:
InChangeMode = False
End Sub
Private Sub Combo1_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case vbKeyBack
BackSpacePressed = True
End Select
End Sub
Private Sub Form_Load()
'Dim idx
'With Combo1
'.Clear
'For idx = 65 To 88
'.AddItem Chr(idx) & Chr(idx + 1) & Chr(idx + 2) & "test"
'Next idx
'End With
InChangeMode = False
BackSpacePressed = False
End Sub
thanx for the help!
Re: Combo Box Autocomplete problem
I'm not sure what you mean by "every combo box command". If you want to use the same code for many combo boxes on the same form then you can create a control array. The structure will look like this:
VB Code:
Private Sub Combo1_Change(Index As Integer)
With Combo1(Index)
' your code in here...
End With
End Sub
Private Sub Combo1_KeyPress(Index As Integer, KeyAscii As Integer)
' more of your code in here...
End Sub
Note sure if that's what you need....
Re: Combo Box Autocomplete problem
hi, thanx for d reply but wat i mean for every combo box command is i will not put dat code in every combo1_change() , combo2_change() etc... i can access it publicly so dat every combo box in my form has autocomplete.
Re: Combo Box Autocomplete problem
That's not possible with a self-contained function. You would need to make an AutoComplete class and then declare a separate class for each combo box. If you want to do it that way I can try an example for ya :)
Re: Combo Box Autocomplete problem
I dnt knw how to make classes... can u make 1 for me.. thanx!
Re: Combo Box Autocomplete problem
Quote:
Originally Posted by psychofoo
I dnt knw how to make classes... can u make 1 for me.. thanx!
t3h LOL!
chem
Re: Combo Box Autocomplete problem
Sorry, but there aren't many people who'll just create a class for you. Besides, wouldn't it be more fun to learn how to do it rather than get away with it being done for you? It's really not that hard at all. Try searching google, or the forums. Once you get the hang of them, they'll become part of nearly every program you write.
@The Rest of us:
I think it's time we covered some of the stuff like API's, Classes, Etc. Unless there are some pretty easy to understand ones already on the forums?
chem
Re: Combo Box Autocomplete problem
Quote:
Originally Posted by penagate
That's not possible with a self-contained function. You would need to make an AutoComplete class and then declare a separate class for each combo box. If you want to do it that way I can try an example for ya :)
I guess he will make an example for me :P :o
1 Attachment(s)
Re: Combo Box Autocomplete problem
Here it is, might have a few bugs but it seems to work.
BTW, I don't usually just write code for people, but in this case it was an example that I already had (part of it anyway) I just wrapped it in a class to show you how it is done. Hopefully you learn something from it for the future :)
Re: Combo Box Autocomplete problem