nakedbamboo
Technical User
I have a combo box where the user chooses the state. I would like to have it act like the combo box everyone is familiar with where if you hit the same letter, it cycles through the choices in that letter. For example, if I hit "O" twice I want it to cycle to Oklahoma instead of typing "OO" in the box, or if I hit it one more time, I want it to cycle to Oregon. I was told I would have to code this as Access does not have this function. I think I have a pretty good start on it, but have run into a snag with setting the value of the combobox. Below is the code so far:
The problem comes at the end when I try to set the value of the combobox equal to the current indexed value. It is not doing this. I have tried using the .Value, .Text, among other things to set this value equal to (State.ItemData(Index)). The msgbox at the end displays the next Index number as hoped for and while the msgbox is showing, the correct state is even shown in the combobox, but as soon as I close the msgbox, the combobox resets to the first state of that letter. By the way, the States are stored as a value list in the combobox to which it is limited. Thanks for any help.
Code:
Private Sub State_KeyDown(KeyCode As Integer, Shift As Integer)
Dim Letter As String
Dim FirstLetter As String
Dim Index As Integer
Index = State.ListIndex
Letter = UCase(Chr(KeyCode))
If Letter <= "Z" And Letter >= "A" Then
If (Letter = Left(State.ItemData(Index), 1)) Then
Index = Index + 1
Else
For Index = 0 To 50
FirstLetter = Left(State.ItemData(Index), 1)
If (Letter = FirstLetter) Then
Exit For
Else
End If
Next Index
End If
State = State.ItemData(Index)
Else
End If
MsgBox (State.ListIndex)
End Sub
The problem comes at the end when I try to set the value of the combobox equal to the current indexed value. It is not doing this. I have tried using the .Value, .Text, among other things to set this value equal to (State.ItemData(Index)). The msgbox at the end displays the next Index number as hoped for and while the msgbox is showing, the correct state is even shown in the combobox, but as soon as I close the msgbox, the combobox resets to the first state of that letter. By the way, the States are stored as a value list in the combobox to which it is limited. Thanks for any help.