Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Disabling Alt-F4 wont work

Status
Not open for further replies.

mark01

Technical User
Jan 17, 2001
600
US
I have the following code to disable Alt-F4...

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
If UnloadMode = 0 Then
Cancel = 1
End If
End Sub

This works fine on a freshly made app, but when I use this code on an existing application with 100's of lines of code, I can close it by pressing Alt-F4 a bunch of times. I really can't have this. Is there another way to ensure the user can't close it by pressing Alt-F4?? or anyone else have this issue?

(I have 2 forms, both have this code place within it, and both are open at the time I hit Alt-F4.)
 
Set form's keypreview to true and try this code:


Option Explicit

Private mintKeycode As Integer

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
mintKeycode = KeyCode
End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Cancel = (mintKeycode = 18) Or (mintKeycode = 115)
If Cancel Then mintKeycode = 0
End Sub

 
The problem I see with just disabling Alt-4 is that the system menu will still show it next to the close command, so it will just seem to the user not to work. It's better to just remove it all together as in the link I provided.

My 2 cents.



Two strings walk into a bar. The first string says to the bartender: 'Bartender, I'll have a beer. u.5n$x5t?*&4ru!2[sACC~ErJ'. The second string says: 'Pardon my friend, he isn't NULL terminated'.
 
Yes, I tried the code in the link. It works. I just wanted to disable Alt F4 only. Who knows, may be contol box still needed: it was not mentioned.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top