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,824 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
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
word 2016 1 30
Modal form 11 29
Obtaining Access 2013 Runtime file for Sagekey 2013 Installer 3 18
Should I keep recordsets open? 3 23
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…
QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

785 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