R
riccifs
Hi to everyone in the N.G.
recently I looking for a way to enhance my combobox behavior and in a
quite old post, I find this code (the one I posted below).
It adds the ability to use a combobox in a web-style.
Image you have a list of items and they start with the same letter.
Each time you press this letter the combo will match sequentially
those items!
My question is:
how can I modify the code below to make it usable with every combo I
add to a form, without repeat the code for each ones? (may be using
Screen.ActiveControll or something like that)
I'm not very with VBA so I need someone will help me!
Thanks a lot,
Stefano.
****Code Starts****
Private Sub cboTopicID_KeyDown(KeyCode As Integer, Shift As Integer)
Static intPrevKeyCode As Integer
'Debug.Print "ComboBox_KeyDown - KeyCode: " & KeyCode & _
' " Shift: " & Shift
With Me.cboTopicID
If (KeyCode = intPrevKeyCode) And (Left(.Column(1, .ListIndex), 1)
= _
Left(.Column(1, .ListIndex + 1), 1)) Then
.ListIndex = .ListIndex + 1
KeyCode = 0
Else
intPrevKeyCode = KeyCode
End If
.Dropdown
End With
End Sub
****Code Ends****
recently I looking for a way to enhance my combobox behavior and in a
quite old post, I find this code (the one I posted below).
It adds the ability to use a combobox in a web-style.
Image you have a list of items and they start with the same letter.
Each time you press this letter the combo will match sequentially
those items!
My question is:
how can I modify the code below to make it usable with every combo I
add to a form, without repeat the code for each ones? (may be using
Screen.ActiveControll or something like that)
I'm not very with VBA so I need someone will help me!
Thanks a lot,
Stefano.
****Code Starts****
Private Sub cboTopicID_KeyDown(KeyCode As Integer, Shift As Integer)
Static intPrevKeyCode As Integer
'Debug.Print "ComboBox_KeyDown - KeyCode: " & KeyCode & _
' " Shift: " & Shift
With Me.cboTopicID
If (KeyCode = intPrevKeyCode) And (Left(.Column(1, .ListIndex), 1)
= _
Left(.Column(1, .ListIndex + 1), 1)) Then
.ListIndex = .ListIndex + 1
KeyCode = 0
Else
intPrevKeyCode = KeyCode
End If
.Dropdown
End With
End Sub
****Code Ends****