Solved

Disable Alt-F4 in Access 2003 (I have code already for CTRL+H.. need it modified to Alt+F4

Posted on 2007-04-06
11
1,934 Views
Last Modified: 2013-11-27
Using Access 2003. Making a FE/BE application.
I tried searching for this specific answer, and although I could find related code, I'm not "smart" enough to change it to my needs.

I simply want to globally (if easy) remove ALT-F4 when in Access or at least use the keydown to trap it.

code I've found is

Private sub form_keydown(keycode as integer, shift as integer)
Dim intcrtl as integer
intctrl = (Shift And acctrlmack) > 0
if intctrl And KeyCode = vbKeyH then
keycode = 0
end if
end sub

1)What do I replace to trap Alt-F4 (or is there a better way?)
2)Also I wouldn't mind understanding what Shift has to do with anything in that code.. the code is for CTRL+H so why do they have Shift in there?

Thx in advance.
0
Comment
Question by:detroitdr
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 2
11 Comments
 
LVL 75
ID: 18868632
Hey ... you're back ... you are in the motor city, right?

mx
0
 
LVL 75
ID: 18868633
It's really simple ... standby ... ...

mx
0
 
LVL 75

Accepted Solution

by:
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform) earned 250 total points
ID: 18868669
OK ... just forget the word 'shift' ... you didn't see ... it does not exist.  What I am saying is ... it was a piss pour choice of words to use for that argument in the Keydown event.  It does NOT mean the Shift Key per se.

Here are the values:

   'Shift Argument for the 7 combinations of Shift, Ctrl and Alt keys:
   '0 None
   '1 Shift Key
   '2 Ctrl Key
   '3 Shift + Ctrl Keys
   '4 Alt Key
   '5 Shift + Alt Keys
   '6 Ctrl + Alt Keys
   '7 Shift + Ctrl + Alt Keys
   '----------------------------------------

OK ... here is solution for a form by form basis first:

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
   
    If (Shift = 4 And KeyCode = vbKeyF4) Then
        KeyCode = 0
        Beep
    End If
   
End Sub

mx


0
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 
LVL 75
ID: 18868709
'Globally' ... slightly different situation.
Sadly ... you cannot trap the ALT key in an AutoKeys macro, otherwise ... you could just create an AutoKeys macro ... and 'beep' that combination out.

Sooooo ... basically ... you could create a gen purpose vba function ... which you would call from every frickin' form/report ... KeyDown event etc ... wherein the you would pass the KeyCode and Shift (opps that WORD again) to that function ...use the code above ... and have the function return ...in essence ... a KeyCode of zero ... if that condition was meant.

Now .... there is a more 'advanced' approach ... that can prevent Access from closing - which is what ALT+F4 does ... but ... that is somewhat beyond the 'if easy' concept :-(

mx
0
 
LVL 75
ID: 18868713
Sooooo .... are we having FUN yet, lol ...

mx
0
 
LVL 75
ID: 18868733
Actually .... re "It's really simple ... standby ... ... "

I was thinking the 'AutoKeys' solution .. but I completely forgot that you cannot trap the ALT key in an AutoKeys macro ... bummer ... so ... it's still somewhat 'simple' ... but .... the 'Global solution ... well ... unfortunately, the Access 'application object' itself does not have any trappable events ... so ... it kind of comes down to the form/report level.  But ... I'm not ruling out 100% that someone here on EE ...one of the many VERY smart and clever members ... doesn't have a 'global' solution???

mx
0
 

Author Comment

by:detroitdr
ID: 18869306
Wow, DatabaseMX,....

you sure have been doing a  great job of answering my questions, Thx
Greatly appreaciate the detailed answer on explaining the "shift" issue.

Thank-you again.
0
 
LVL 58
ID: 18869328
<<1)What do I replace to trap Alt-F4 (or is there a better way?)>>

  Trapping the key in the AutoKeys macro would have been the simplest.

JimD
0
 
LVL 75
ID: 18869820
Jim .... you cannot trap the ALT key in AutoKeys.  Even though there is an MSDN article wherein they mention using %+ALT for something ... if you put %ALT{F4}  (or any key) ... you cannot save the macro.  Believe me, I tried. And ... that is what I was thinking in my first post when I said 'this is simple'.

The reason is because of all the ALT+<somekey> than you can use to create shortcuts ...when you underline a character in a label, etc.

mx
0
 
LVL 75
ID: 18869825
Det ... you are welcome.  I've almost has too much experience with that 'shift' key!  Remember, just say no to calling it 'shift', lol.

mx
0
 
LVL 58
ID: 18869954
<<.... you cannot trap the ALT key in AutoKeys>>

  Your right...never really tried I guess.  Kinda strange actually that you can with Key Preview and not with the Autokeys.  Really doesn't make sense.

  and sorry I missed you comment on Autokeys the first time around.

JimD
0

Featured Post

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question