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

Expert Comment

by:DatabaseMX (Joe Anderson - Access MVP)
Comment Utility
Hey ... you're back ... you are in the motor city, right?

mx
0
 
LVL 75

Expert Comment

by:DatabaseMX (Joe Anderson - Access MVP)
Comment Utility
It's really simple ... standby ... ...

mx
0
 
LVL 75

Accepted Solution

by:
DatabaseMX (Joe Anderson - Access MVP) earned 250 total points
Comment Utility
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

Expert Comment

by:DatabaseMX (Joe Anderson - Access MVP)
Comment Utility
'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

Expert Comment

by:DatabaseMX (Joe Anderson - Access MVP)
Comment Utility
Sooooo .... are we having FUN yet, lol ...

mx
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 75

Expert Comment

by:DatabaseMX (Joe Anderson - Access MVP)
Comment Utility
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
Comment Utility
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

Expert Comment

by:Jim Dettman (Microsoft MVP/ EE MVE)
Comment Utility
<<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

Expert Comment

by:DatabaseMX (Joe Anderson - Access MVP)
Comment Utility
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

Expert Comment

by:DatabaseMX (Joe Anderson - Access MVP)
Comment Utility
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

Expert Comment

by:Jim Dettman (Microsoft MVP/ EE MVE)
Comment Utility
<<.... 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

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.

Join & Write a Comment

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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 …

771 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

12 Experts available now in Live!

Get 1:1 Help Now