JamesJ said:
Thanks. I have a DoubleClick for the list box but wanted to have the same
action occur when I hit the Enter key.
I just needed to change your If statement line in your example to:
Private Sub lstDesc_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbReturn Then
'Code here
End If
End Sub
This seems to work fine.
Thanks,
James
Yes it'll work, but it's due more to luck than management. The KeyCode
values that are delivered to the KeyDown event are very different to the
KeyAscii values in the KeyPress event. In KeyDown the codes represent the
electronic scan codes emitted by the keyboard's circuitry. In KeyPress the
codes represent the ASCII code of all the printable keys (and a few others).
It just so happens that KeyAscii vbReturn = 13 and KeyCode vbKeyReturn = 13.
Therefore I think your code ought to read either:
Private Sub lstDesc_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyReturn Then
KeyAscii = 0
lstDesc_DblClick False
End If
End Sub
or:
Private Sub lstDesc_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyReturn Then
KeyCode = 0
lstDesc_DblClick False
End If
End Sub
Take your pick.