MiBlg
asked on
How to Trap <Enter> key in DateTime Picker
Hi,
I'm wondering how a DateTime Picker control can trap a <Enter> key. I want a DateTime Picker control can response to <Enter> key so that it can move current focus to another control (has same effect as pressing <Tab> key).
In the KeyPress event of DateTime picker I do this:
if (KeyAscii = 13) then
SendKeys "{Tab}"
KeyAscii = 0
end if
This code successfully run on TextBox & ComboBox control, but it fails on DateTime picker control. Any ideas?
Thanks in advance
MI
I'm wondering how a DateTime Picker control can trap a <Enter> key. I want a DateTime Picker control can response to <Enter> key so that it can move current focus to another control (has same effect as pressing <Tab> key).
In the KeyPress event of DateTime picker I do this:
if (KeyAscii = 13) then
SendKeys "{Tab}"
KeyAscii = 0
end if
This code successfully run on TextBox & ComboBox control, but it fails on DateTime picker control. Any ideas?
Thanks in advance
MI
Try the KeyDown event?
Private Sub DTPicker1_KeyUp(KeyCode As Integer, Shift As Integer)
If (KeyCode = 13) Then
SendKeys "{Tab}"
KeyCode = 0
End If
End Sub
If (KeyCode = 13) Then
SendKeys "{Tab}"
KeyCode = 0
End If
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
hello MiBlg !
How about centralisation of your chr(13) to chr(9)- code ?
If you have a DtPicker you have also a form, say Form1.
Suggestion:
Form1.KeyPreview=True
Private sub Form1_Keydown (KeyCode As Integer, Shift As Integer)
If (KeyCode = vbKeyReturn) Then
SendKeys "{Tab}"
KeyCode = 0
End If
end sub
V.K.
How about centralisation of your chr(13) to chr(9)- code ?
If you have a DtPicker you have also a form, say Form1.
Suggestion:
Form1.KeyPreview=True
Private sub Form1_Keydown (KeyCode As Integer, Shift As Integer)
If (KeyCode = vbKeyReturn) Then
SendKeys "{Tab}"
KeyCode = 0
End If
end sub
V.K.