From: David on
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

Maybe getting outside of VB's design criteria, but above would
eliminate need for some buttons.

David



"Helmut Meukel" <NoSpam(a)NoProvider.de> wrote in message
news:%23oZe3q%23zKHA.4752(a)TK2MSFTNGP04.phx.gbl...
> David,
>
> setting a command buttons Cancel property to True generates
> automatically a click for this command button whenever the user
> presses the Escape key.
>
> So the code in the command buttons click event just has to handle
> whatever should be done when the user presses Escape.
> I you name the command button "Cancel" and make it visible to
> the user he can either click on the command button or press
> Escape.
> If you don't want this Cancel button visible, move it out of sight
> by setting either Top or Left to a suffient high negative value.
> Its Visible property must stay True, but you should remove it
> from the Tab order by setting its TabStop property to False.
>
> Another approach would be - as Karl suggested - to use the
> forms KeyPreview property. Look it up in Online Help.
>
> Helmut.
>
>
> "David" <NoWhere(a)earthlink.net> schrieb im Newsbeitrag
> 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.
>>
>> David
>
>


From: Nobody on
"David" <NoWhere(a)earthlink.net> wrote in message
news:epPCoZB0KHA.6140(a)TK2MSFTNGP05.phx.gbl...
> 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
>
> Maybe getting outside of VB's design criteria, but above would
> eliminate need for some buttons.

You may want to simplify your design. Instead of providing Save button that
the user must click on in order to save, provide OK/Cancel buttons like many
other applications. If the user closed the form, auto save the result by
calling btnOK_Click. If the user didn't enter valid information, set Cancel
= True in Form_QueryUnload.

If you want to tell if a text box has been modified, send EM_GETMODIFY to
it. Search the web for "vb EM_GETMODIFY" for samples.


From: Dave O. on

"Nobody" <nobody(a)nobody.com> wrote in message
news:%23pHnNjB0KHA.5036(a)TK2MSFTNGP02.phx.gbl...

> If you want to tell if a text box has been modified, send EM_GETMODIFY to
> it. Search the web for "vb EM_GETMODIFY" for samples.

Whilst that works it is a bit inelegant because for example if you have a
text box and the content is changed that will return a positive, but if you
then edit the text box again so it contains what it originally contained
then that call will still return a positive.
An alternative could be to copy the content into the tag and then compare
the content with the tag, that way you only get a positive if the content is
actually different.

Regards
Dave O.


From: Jeff Johnson on
"David" <NoWhere(a)earthlink.net> wrote in message
news:epPCoZB0KHA.6140(a)TK2MSFTNGP05.phx.gbl...

> 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
>
> Maybe getting outside of VB's design criteria, but above would
> eliminate need for some buttons.

No, you can't do that. What you want is the opposite of what VB will give
you. The Esc key triggers the Click event. The Click event has absolutely no
idea HOW it was triggered.

I personally feel that the hidden button with Cancel = True is cheesy,
cheesy, cheesy. Use KeyPreview, plain and simple.


From: Helmut Meukel on
David,

I don't think it's a good approach, but the following code should
do what you want.
In your form:

Option Explicit
Private EscapeFlag As Boolean

Private Sub CommandSave_Click()
If EscapeFlag Then
'the user pressed Escape


EscapeFlag = False 'reset the EscapeFlag
Else
'the user clicked on Save

End If

End Sub

Private Sub Form_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyEscape Then
KeyAscii = 0
EscapeFlag = True
CommandSave.Value = True
End If
End Sub

For this to work, set Cancel = False for the command button,
because the Cancel property set to True interferes with the
ability of the form to catch the Ecsape key!

Helmut.


"David" <NoWhere(a)earthlink.net> schrieb im Newsbeitrag
news:epPCoZB0KHA.6140(a)TK2MSFTNGP05.phx.gbl...
> 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
>
> Maybe getting outside of VB's design criteria, but above would
> eliminate need for some buttons.
>
> David
>
>