I want to hide the Pop-up Calendar on my Access form by pressing the Escape
key
In the tutorial A Pop-up
Calendar for your Access Forms I showed how you could use the ActiveX
calendar control to add a pop-up calendar to a form. The calendar is placed on
the form just like any other control but remains hidden until the user clicks a
specific field, when the calendar becomes visible. Choosing a date from the
calendar hides it again. But what if you didn't mean to open the calendar... how
can you hide it without choosing a date?
Access forms and their controls can be programmed to respond to keyboard
events. The KeyPress event is usually used to respond to normal
characters such as letters or numbers. The KeyDown and KeyUp
events are usually used to handle the "special" keys like Ctrl,
Alt and Shift.
Let's program the form to respond to the Escape key by hiding the
calendar:

There are two If Statements. The first checks to see if the calendar control
is visible, and if it isn't the procedure finishes without doing anything. But
if the calendar control is visible the second If Statement checks which key was
pressed. If it was the Escape (ESC) key then two things happen. First, the focus
gets transferred back to a control on the form (because we're about to hide a
control and you can't hide a control that has the focus), then the calendar
control is hidden and the procedure finishes.
There's another important thing you have to do to make this work. Set the
Key Preview property of the form to Yes. You'll find it on the
"Event" tab of the form's property sheet. This causes the form to "intercept"
key presses before they are received by the form's active control and ensures
that your chosen action gets priority.

I chose to use the Escape key in this instance, because it is what most users
would expect. To see a list of the names and numerical values used to identify
keys, ask Visual Basic Help about Keycode Constants.
|