Author Topic: ESC in sub  (Read 2321 times)

0 Members and 1 Guest are viewing this topic.

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
ESC in sub
« on: February 12, 2007, 02:14:17 PM »
OK, maybe I dont get it, but how can you trap the ESC key in a form?  What I'm trying to do is trap whether a user hits ESC in one of my subs.  Let me back up first, I have a form, that when a user clicks a button, it calls a sub in a module.  What I'm trying to avoid is 50 public subs.  What I want is to call a private sub.  Since you cant call a private sub in a differnt module, do I need to get rid of my modules and put everything in the code portion of the form?  Is there anything wrong with this approach?  When I tried to declare a constant for the ESC key, you can't declare constants in the form object. (Or else I'm doing that wrong as well)  Im trying to use RR's routine from this post.

Any ideas....
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: ESC in sub
« Reply #1 on: February 12, 2007, 03:17:29 PM »
I still don't understand what you are trying to do ... Are you trying to stop a person from hitting the ESC key and exiting a form? I don't think it works that way .. but, you can grab the value in queryclose and keep the form open, if you simply want to know if the user pressed the esc key, you should be able to return the value from the KeyDown event, but it is pretty funny and I don't trust it
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
Re: ESC in sub
« Reply #2 on: February 12, 2007, 03:39:02 PM »
I still don't understand what you are trying to do ...
I had no error handler for If the user pressed ESC.  If you do, it generates an Unhandled Err Exp.  Thus, I was trying to handle it gracefully.  What I have ended up doing as a test is to put the code in each module (1 for now as a test) and I have begun testing every which way to press the ESC key and seeing if it catches it.

On a side note, I have changed all my subs to Functions, and that removed them from the list of macros that can be run.  Any downside to this?  I always use subs when there is no value returned, and Functions when I want to return a value.  In C#, you can declare it VOID, but VBA doesn't use that (not that I'm aware of).
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: ESC in sub
« Reply #3 on: February 12, 2007, 04:12:59 PM »
Have you tried keyboard hooks or GetAsyncKeyState?

Try looking at these two articles, I would post an example, but it is much to complex to post here.
http://www.codeguru.com/vb/gen/vb_system/keyboard/print.php/c4829/
http://www.pscode.com/vb/scripts/ShowCode.asp?txtCodeId=41506&lngWId=1
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
Re: ESC in sub
« Reply #4 on: February 12, 2007, 04:27:13 PM »
Have you tried GetAsyncKeyState?

Yes, thats what I used
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)