Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
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
Medium Priority
?
2,060 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 1000 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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
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…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

610 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