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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Disabling all Exit options on Access 1

Status
Not open for further replies.

taiwai94

Programmer
Jul 8, 2005
20
GB
Hello,

I found an interesting thread but unfortunately it has been archived so I can not ask my question there. For some time, I have been looking for a way to disable all exit optionson Access, except for a button on my database menu bar, which is the only a user should exit. The original thread is:


I have already got code to disable the [X]in the top right corner but I wish to disable the File|Exit option and the ALT+F4 option. My knowledge of of VB ranges from nominal to none. I have tried with various scripts but I have never got anything to work.

Can someone please explain how to do it in ultra-simple or idiot's guide explaining which code goes where, which macros do what and what forms contain what code. I think certain websites assume readers know enough to actually know what they're talking about, but I have no idea.

SOS please someone?

Taiwai94
 
If your application is fully secured (you've implemented Jet Security) you can customise all built in CommandBars (drop down menus, toolbars and shortcut menus) removing references to the Exit (Application.Quit) command or create full custom CommandBars and point all Form CommandBar related properties to these for all your forms.

Then set AllowMenuBarChanges = False in the database StartUp Options dialogue box. You can also set this and all other start up properties programmatically:


You must set AllowSpecialKeys = False so that the user can't display the database window by pressing Shift on application start up, or use ALT+F1 (F11) to bring the Database window to the front.

You can trap Key Strokes and kill them by setting the Form KeyPreview property to True and inserting the following code into the OnKeyDown Event property:

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
On Error GoTo Err_Form_KeyDown

If Shift = acAltMask Then
If KeyCode = vbKeyF4 Then
KeyCode = 0
End If
End If

Exit_Form_KeyDown:
Exit Sub

Err_Form_KeyDown:
MsgBox "Form_KeyDown Error: " & Err.Number & ": " & Err.Description
Resume Exit_Form_KeyDown
End Sub

Setting a reference in the OnOpen Event (of each form) to a custom class module which populates a Form variable using the WithEvents argument will save you pasting the above code in Form module. I'll leave you to explore this but this will get you started:

Regards


Ian
 
Thank-you Ian, that was very insightful! "*"
 
Yeah, sorry about that(!). The questions you've been asking appear small, but aren't, and it's going to require someone to do a fair bit of work - ain't that always the case?!! There are a lot of issues around restricting user options in Access and I haven't seen all of them grouped together except in publications like the Access Developers Handbook by Litwin, Getz & Gilbert which is a good investment.

One thing I have learnt from building my own applications is that classing will siginificantly reduce the amount of coding you have to do. You can use a class module to assign properties and procedures (by sinking events) to all your Forms painlessly. It just takes one line to create a new instance of the class in each Forms Form_Open Event.

All The Best


Ian
 
jkl0,

Thanks for that little bit of code, it works wonders except for one small bug. Obviously, the message prevents access from being shut down. On the database, I have a button which when pressed runs a marco which runs the Quit command.

Since applying the code, this database button is the only way to actually close the database down. However, the message pops up when this is pressed (and this is the one time it shouldn't pop up). Is there anyway to add code onto this button to still run the macro but kill the message so it doesn't appear?

Thanks very much,

Taiwai94
 
I have not personally tested this method but maybe one of the other knowlegable guru's can suggest a more complete method.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top