Link to home
Start Free TrialLog in
Avatar of MiBlg
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
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Try the KeyDown event?
Avatar of supunr
supunr

Private Sub DTPicker1_KeyUp(KeyCode As Integer, Shift As Integer)
If (KeyCode = 13) Then
  SendKeys "{Tab}"
  KeyCode = 0
End If
End Sub
ASKER CERTIFIED SOLUTION
Avatar of MickyMc
MickyMc
Flag of Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.