Code multiple forms simultaneously

  • Thread starter Thread starter Paul3rd
  • Start date Start date
P

Paul3rd

Hello, several of the users of my application have asked that the escape key
be used to close a form.
My application has 45 forms, is there a way I can change the KeyPreview
property to Yes and insert the small bit of code to the KeyPress event of all
the forms simultaneously?
Thanks in advance for any help
Paul
 
I suppose one approach might be to create a general code module that closes
a form, then call that procedure from each form.

I'm not aware of a way to do all the forms at once.

Good luck!

Regards

Jeff Boyce
Microsoft Office/Access MVP
 
You can't do that all at the same time. I would advise against using the
Escape key. It is special meaning in Access. When a form is open, pressing
it once performs an Undo on the current control. Pressing it twice performs
an Undo on the current record. I have not really tested it, but I think
there may be problems with using the Escape key for closing a form.

There is a way using some other key combination that would allow you to
close the Active form without having to modify code in any of your forms. As
a test, I created and AutoKeys macro with a key combination of <ctrl><Q>.
You enter it in as ^Q. Then for the action, use RunCode and enter
CloseTheForm

Here is the code you would put in a standard module to perform the close:

Public Function CloseTheForm()
DoCmd.Close acForm, Screen.ActiveForm.Name, acSaveNo
End Function
 
Certainly that is the usual way to accomplish that. The only problem is the
OP was looking for a way to not have to put the code in every form.
Since the AutoKeys marco will not allow the use of the Escape key, my
solution will not be useful if he has to use the Escape key.
 
Back
Top