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,795 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
  • 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 - Access MVP) 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
 
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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
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 57
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 57
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

920 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now