PDA

View Full Version : Activate Esc key in Calendar userform



rajagopal
06-28-2007, 11:29 PM
I've a calendar userform pop-up when user select cell range L60:L69.
When user press Esc key, the calendar should disappear.
I've the code like this.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim Rng1 As Range
'Assign the range to work with
Set Rng1 = Range("L60:L69")

'Only work on assigned range
If Intersect(Target, Rng1) Is Nothing Then Exit Sub
'Call the userform
UserForm1.Show
End Sub

Please help

Regards

mikerickson
06-29-2007, 01:15 AM
Put this in the code module for the Userform. Pressing the escape key will unload the userform.
Private Sub UserForm_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
If KeyCode = 27 Then Unload Me
End Sub

rajagopal
06-29-2007, 02:15 AM
I've put it in code module of the user form but didn't have any effect

Regards

anandbohra
06-29-2007, 04:47 AM
hi mikerickson

the same happens with me when i try it to a blank form your code unload the user form
but when i try it to form which has calender object

no unload takes place pl help

mikerickson
06-29-2007, 05:45 AM
It works on my machine, it sounds like a cross-platform issue. What happens when you put this in the userform's module and press ESC?

Private Sub UserForm_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
MsgBox KeyCode
End Sub

Ivan F Moala
06-29-2007, 03:33 PM
put the code in the calendar key down event as the UF doesn't have focus

anandbohra
07-01-2007, 09:50 PM
Good Logic Ivan F Moala (http://www.vbaexpress.com/forum/member.php?u=19)

the default focus was on calender object that is why the form is not unloading

Thanks mikerickson for the code & Thanks Ivan F Moala (http://www.vbaexpress.com/forum/member.php?u=19) for giving hint for focus on calendar object.

geekgirlau
07-01-2007, 09:54 PM
I find in a user form it's helpful to have a "Cancel" command button, where Cancel is set to True - the user then knows there is a way to cancel out of the form, and can either click on the button or press Esc.

rajagopal
07-01-2007, 11:59 PM
hi mikerickson
I've tried with both of your codes. But no effect.
Based on Ivan's input, i modified the code as Private Sub calendar_KeyDown....
But still pressing the Esc key do not have any effect?

Please help.

Regards
Raj

rajagopal
01-06-2009, 04:20 AM
Hi,
The calendar userform was working fine but I'm getting an error message now. Please help.
I attached the screenshot.

Bye

lucas
01-06-2009, 09:13 AM
FYI start reading at post #7
http://www.vbaexpress.com/forum/showthread.php?t=10914