From: Daryl Muellenberg on 30 Mar 2010 12:26 "David" <NoWhere(a)earthlink.net> wrote in message news:eOBR1F7zKHA.6140(a)TK2MSFTNGP05.phx.gbl... > Mr. Petersons "Key Preview" reminder resolved things easily. > > Mr. Toews and MikeD. > > Out of curiousity and future need, is there anyway to code for the "Esc" > key in the command_click event? > If you can trap it in command_click, would definitely reduce need for > multiple command buttons. > This is not a good idea if your app is designed for general (not personal) use. The Cancel button is standard and the user knows the purpose of the button. Without the button on the screen, how does the user know that the Esc key cancels his/her changes?
From: David Youngblood on 30 Mar 2010 12:39 "David" <NoWhere(a)earthlink.net> wrote... > As always thanks to all for input. > > Understand the KeyPreview and QueryUnload as well as setting > Cancel True in command button. > > Where I was going with this was using one command button called cmdSave > where Cancel = True. > > Then in "cmdSave_Click" doing something like: > > If KeyAscii = 27 Then '<<Yes I know KeyAscii is not available here > 'Escape was pressed do whatever > Else > 'Call your save procedure. > End If I don't see the point, but if that's what you want you might try GetAsyncKeyState. Private Declare Function GetAsyncKeyState Lib "user32" ( _ ByVal vKey As Long) As Integer Private Const VK_ESCAPE = &H1B Private Const VK_RETURN = &HD Private Sub Form_Load() Command1.Cancel = True Command1.Default = True End Sub Private Sub Command1_Click() If GetAsyncKeyState(VK_ESCAPE) Then Debug.Print "Escape was pressed" ElseIf GetAsyncKeyState(VK_RETURN) Then Debug.Print "Enter was pressed" Else Debug.Print "Button was clicked" End If End Sub David
From: Karl E. Peterson on 30 Mar 2010 13:10 Daryl Muellenberg wrote: > "David" <NoWhere(a)earthlink.net> wrote... >> Mr. Petersons "Key Preview" reminder resolved things easily. >> >> Mr. Toews and MikeD. >> >> Out of curiousity and future need, is there anyway to code for the "Esc" >> key in the command_click event? >> If you can trap it in command_click, would definitely reduce need for >> multiple command buttons. > > This is not a good idea if your app is designed for general (not personal) > use. The Cancel button is standard and the user knows the purpose of the > button. Without the button on the screen, how does the user know that the Esc > key cancels his/her changes? Only programmers associate the Escape key with a button. Users just see it as another way to dismiss a form. -- ..NET: It's About Trust! http://vfred.mvps.org
From: David on 30 Mar 2010 13:58 OK guys, guess I'm getting away from standards "a little". The way I approached this, and works quite well, is: 1) Bring up form with associated controls. This is for viewing only. 2) If the user wishes to alter a control contents (textbox in this case) they go to the Edit menu and select Edit (allows altering of textbox contents) -- or -- Add (clears the textbox and allows input). 3) When Edit menu is selected a cmdButton appears (Caption is not an issue -- OK or Save does it). 4) Right now with KeyPreview ("Esc") I hide the cmdButton and disable Edit mode. Putting you back into view only. 5) Exit of Form is handled from file menu or "X" 6) The use of a listbox on the left allow user to repopulate textbox contents with the info associated with that list item. Original thought -- instead of KeyPreview -- was to trap "Esc" just like KeyPreview. I do agree that setting Cancel = True is "kinda flaky" and definitely not intuitive (to any followon programmer). Again, thanks to all for your time and effort on my behalf. David "Karl E. Peterson" <karl(a)exmvps.org> wrote in message news:u3e$ovC0KHA.6124(a)TK2MSFTNGP02.phx.gbl... > Daryl Muellenberg wrote: >> "David" <NoWhere(a)earthlink.net> wrote... >>> Mr. Petersons "Key Preview" reminder resolved things easily. >>> >>> Mr. Toews and MikeD. >>> >>> Out of curiousity and future need, is there anyway to code for the "Esc" >>> key in the command_click event? >>> If you can trap it in command_click, would definitely reduce need for >>> multiple command buttons. >> >> This is not a good idea if your app is designed for general (not >> personal) use. The Cancel button is standard and the user knows the >> purpose of the button. Without the button on the screen, how does the >> user know that the Esc key cancels his/her changes? > > Only programmers associate the Escape key with a button. Users just see > it as another way to dismiss a form. > > -- > .NET: It's About Trust! > http://vfred.mvps.org > >
From: Jeff Johnson on 30 Mar 2010 15:20
"Daryl Muellenberg" <dmuellenberg(a)comcast.net> wrote in message news:33FB3D6D-9976-4EA8-9295-D0B942EFBD66(a)microsoft.com... > This is not a good idea if your app is designed for general (not personal) > use. The Cancel button is standard and the user knows the purpose of the > button. Without the button on the screen, how does the user know that the > Esc key cancels his/her changes? There are lots of applications where Esc is used in this way. Off the top of my head: Access. |