Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1272
  • Last Modified:

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
0
MiBlg
Asked:
MiBlg
1 Solution
 
Ryan ChongCommented:
Try the KeyDown event?
0
 
supunrCommented:
Private Sub DTPicker1_KeyUp(KeyCode As Integer, Shift As Integer)
If (KeyCode = 13) Then
  SendKeys "{Tab}"
  KeyCode = 0
End If
End Sub
0
 
MickyMcCommented:
Close chap... try this ... in the KeyDown event. You want to process the Key before the control does so chat it in the Keydown. All the best...Mick

Private Sub dtpDate_KeyDown(KeyCode As Integer, Shift As Integer)
   If (KeyCode = vbKeyReturn) Then
     SendKeys "{Tab}"
     KeyCode = 0
   End If
End Sub
0
 
VKCommented:
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.
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now