Simulating an OnClick Event

  • Thread starter Thread starter Ian Millward
  • Start date Start date
I

Ian Millward

How do I simulate an onclick event from the keyboard. As my user tabs
through several date entry textboxes, which are locked to prevent mistyped
date formats, I have a popup calendar to enter the date. They need to mouse
click on the selected field to execute the calendar FormOpen command. What I
had in mind was to tab through to the field they want and to press the space
bar or, some other combination of keys, to simulate the mouse click.. I
thought that vbKeyExecute sounded like a good bet but can't find any
documentation telling me what it's function is.

Any ideas?

Ian Millward
Edinburgh
 
You can use the KeyDown event of the Control to detect any keystrokes - just
intercept the one you want to use to pull up th calendar form. First be sure
to set the KeyPreview property of the form. Here's a sample event that
intercepts Alt-d - you can revise to intercept any combination of Alt,
shift, Ctl and another keyboard character.

Private Sub odate_KeyDown(KeyCode As Integer, Shift As Integer)
Dim fAlt As Boolean
Dim fShift As Boolean
Dim fCtl As Boolean

fAlt = Shift And acAltMask
fShift = Shift And acShiftMask
fCtl = Shift And acCtrlMask

If KeyCode = vbKeyD And fAlt Then
'Your code goes here
MsgBox "Pressed Alt d"
'Clear the key stroke
KeyCode = 0
End If

End Sub
 
Hello Ian,

How about setting the Tab Stop property of the textboxes to No and creating a
small command button beside each textbox. There's a calendar icon you can put on
the buttons. You can then put the buttons in the tab order. This makes it more
obvious to the user as to what action is needed.
 
<< You can use the KeyDown event of the Control to detect any keystrokes -
just
intercept the one you want to use to pull up th calendar form. First be
sure
to set the KeyPreview property of the form. Here's a sample event that
intercepts Alt-d - you can revise to intercept any combination of Alt,
shift, Ctl and another keyboard character.>>


Spot on.

Many thanks

Ian Millward
 
Back
Top