Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 45
Default Pressing Esc to make a form disappear

I have a form with the usual OK and Cancel buttons. To problems
whatsoever with those buttons. But I have a finicky user who asks if
he can just make the form disappear by pressing the Esc key (he
doesn't want to have to move his mouse to the Cancel button and click,
or use an Alt + accelerator key, or use the tab key to go there. As I
said, he's finicky.)

I'm drawing a blank on how to have Excel read an Esc key as a trigger
to hide and unload the form. Any suggestions?

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Pressing Esc to make a form disappear

You can use the .cancel property for that commandbutton. You can change it in
the properties window (for that commandbutton).

Or you can use code:

Option Explicit
Private Sub CommandButton1_Click()
MsgBox "Hi from Ok"
End Sub
Private Sub CommandButton2_Click()
Unload Me
End Sub
Private Sub UserForm_Initialize()
With Me.CommandButton1
.Caption = "Ok"
.Default = True
End With

With Me.CommandButton2
.Caption = "Cancel"
.Cancel = True
End With
End Sub




jayray wrote:

I have a form with the usual OK and Cancel buttons. To problems
whatsoever with those buttons. But I have a finicky user who asks if
he can just make the form disappear by pressing the Esc key (he
doesn't want to have to move his mouse to the Cancel button and click,
or use an Alt + accelerator key, or use the tab key to go there. As I
said, he's finicky.)

I'm drawing a blank on how to have Excel read an Esc key as a trigger
to hide and unload the form. Any suggestions?


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 45
Default Pressing Esc to make a form disappear

On Jul 29, 5:04*pm, Dave Peterson wrote:
You can use the .cancel property for that commandbutton. *You can change it in
the properties window (for that commandbutton).

Or you can use code:

Option Explicit
Private Sub CommandButton1_Click()
* * MsgBox "Hi from Ok"
End Sub
Private Sub CommandButton2_Click()
* * Unload Me
End Sub
Private Sub UserForm_Initialize()
* * With Me.CommandButton1
* * * * .Caption = "Ok"
* * * * .Default = True
* * End With

* * With Me.CommandButton2
* * * * .Caption = "Cancel"
* * * * .Cancel = True
* * End With
End Sub

jayray wrote:

I have a form with the usual OK and Cancel buttons. To problems
whatsoever with those buttons. But I have a finicky user who asks if
he can just make the form disappear by pressing the Esc key (he
doesn't want to have to move his mouse to the Cancel button and click,
or use an Alt + accelerator key, or use the tab key to go there. As I
said, he's finicky.)


I'm drawing a blank on how to have Excel read an Esc key as a trigger
to hide and unload the form. Any suggestions?


--

Dave Peterson


I meant to say "No problems whatsoever with the OK and Cancel
buttons".

Thanks for the reply. The problem I am trying to solve is to make the
form disappear WITHOUT pressing either the OK or Cancel buttons on the
form. I would like the form to disappear by pressing the Esc key.
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Pressing Esc to make a form disappear

What happened when you tried the suggestion?

jayray wrote:

On Jul 29, 5:04 pm, Dave Peterson wrote:
You can use the .cancel property for that commandbutton. You can change it in
the properties window (for that commandbutton).

Or you can use code:

Option Explicit
Private Sub CommandButton1_Click()
MsgBox "Hi from Ok"
End Sub
Private Sub CommandButton2_Click()
Unload Me
End Sub
Private Sub UserForm_Initialize()
With Me.CommandButton1
.Caption = "Ok"
.Default = True
End With

With Me.CommandButton2
.Caption = "Cancel"
.Cancel = True
End With
End Sub

jayray wrote:

I have a form with the usual OK and Cancel buttons. To problems
whatsoever with those buttons. But I have a finicky user who asks if
he can just make the form disappear by pressing the Esc key (he
doesn't want to have to move his mouse to the Cancel button and click,
or use an Alt + accelerator key, or use the tab key to go there. As I
said, he's finicky.)


I'm drawing a blank on how to have Excel read an Esc key as a trigger
to hide and unload the form. Any suggestions?


--

Dave Peterson


I meant to say "No problems whatsoever with the OK and Cancel
buttons".

Thanks for the reply. The problem I am trying to solve is to make the
form disappear WITHOUT pressing either the OK or Cancel buttons on the
form. I would like the form to disappear by pressing the Esc key.


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 45
Default Pressing Esc to make a form disappear

On Jul 29, 8:23*pm, Dave Peterson wrote:
What happened when you tried the suggestion?





jayraywrote:

On Jul 29, 5:04 pm, Dave Peterson wrote:
You can use the .cancel property for that commandbutton. *You can change it in
the properties window (for that commandbutton).


Or you can use code:


Option Explicit
Private Sub CommandButton1_Click()
* * MsgBox "Hi from Ok"
End Sub
Private Sub CommandButton2_Click()
* * Unload Me
End Sub
Private Sub UserForm_Initialize()
* * With Me.CommandButton1
* * * * .Caption = "Ok"
* * * * .Default = True
* * End With


* * With Me.CommandButton2
* * * * .Caption = "Cancel"
* * * * .Cancel = True
* * End With
End Sub


jayraywrote:


I have a form with the usual OK and Cancel buttons. To problems
whatsoever with those buttons. But I have a finicky user who asks if
he can just make the form disappear by pressing the Esc key (he
doesn't want to have to move his mouse to the Cancel button and click,
or use an Alt + accelerator key, or use the tab key to go there. As I
said, he's finicky.)


I'm drawing a blank on how to have Excel read an Esc key as a trigger
to hide and unload the form. Any suggestions?


--


Dave Peterson


I meant to say "No problems whatsoever with the OK and Cancel
buttons".


Thanks for the reply. The problem I am trying to solve is to make the
form disappear WITHOUT pressing either the OK or Cancel buttons on the
form. I would like the form to disappear by pressing the Esc key.


--

Dave Peterson- Hide quoted text -

- Show quoted text -


Hey...what the...WOW! My apologies. I couldn't see where the magic
was (I still don't). Thanks very much.


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 45
Default Pressing Esc to make a form disappear

On Jul 30, 1:00*pm, jayray wrote:
On Jul 29, 8:23*pm, Dave Peterson wrote:





What happened when you tried the suggestion?


jayraywrote:


On Jul 29, 5:04 pm, Dave Peterson wrote:
You can use the .cancel property for that commandbutton. *You can change it in
the properties window (for that commandbutton).


Or you can use code:


Option Explicit
Private Sub CommandButton1_Click()
* * MsgBox "Hi from Ok"
End Sub
Private Sub CommandButton2_Click()
* * Unload Me
End Sub
Private Sub UserForm_Initialize()
* * With Me.CommandButton1
* * * * .Caption = "Ok"
* * * * .Default = True
* * End With


* * With Me.CommandButton2
* * * * .Caption = "Cancel"
* * * * .Cancel = True
* * End With
End Sub


jayraywrote:


I have a form with the usual OK and Cancel buttons. To problems
whatsoever with those buttons. But I have a finicky user who asks if
he can just make the form disappear by pressing the Esc key (he
doesn't want to have to move his mouse to the Cancel button and click,
or use an Alt + accelerator key, or use the tab key to go there. As I
said, he's finicky.)


I'm drawing a blank on how to have Excel read an Esc key as a trigger
to hide and unload the form. Any suggestions?


--


Dave Peterson


I meant to say "No problems whatsoever with the OK and Cancel
buttons".


Thanks for the reply. The problem I am trying to solve is to make the
form disappear WITHOUT pressing either the OK or Cancel buttons on the
form. I would like the form to disappear by pressing the Esc key.


--


Dave Peterson- Hide quoted text -


- Show quoted text -


Hey...what the...WOW! *My apologies. I couldn't see where the magic
was (I still don't). Thanks very much.- Hide quoted text -

- Show quoted text -


I see the magic is changing the properties of the Cancel button to
True (which is what you said at the very beginning. Obviously a case
of pearls before swine).

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Pressing Esc to make a form disappear

You found the magic for the ".cancel = true" bit, but what does the ".default =
true" stuff do?



jayray wrote:

<<snipped
I see the magic is changing the properties of the Cancel button to
True (which is what you said at the very beginning. Obviously a case
of pearls before swine).


--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Closing Form on pressing Enter or Return-key [email protected] Excel Programming 2 October 11th 07 11:57 AM
closing form when pressing escape key Khaled Excel Programming 1 September 20th 07 01:30 PM
How do you make the cursor go to a designated spot after pressing. Bustasinclair Excel Discussion (Misc queries) 3 September 21st 06 12:59 AM
how to make a form self disappear Ben Excel Programming 1 November 18th 05 09:21 PM
Pressing Enter/Tab to go next question in a form Rachel Setting up and Configuration of Excel 4 October 3rd 05 11:16 PM


All times are GMT +1. The time now is 06:41 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"