I have a form with the min/max/close buttons disabled. The problem is some of my users have figured out how to right click the app on the windows taskbar and close the form. They also close access often by mistake and of course the form closes too. I have tried to teach my users what they're doing wrong but it keeps happening. I need to "idiot proof" my db. I want to impliment a msgbox that asks before the form is closed. Then if they close the form, or access by mistake they can click NO and nothing will be close.
ANY IDEAS??
What are you doing to prevent the user's from accessing your db objects (tool bars, menu bars, db window, etc)?
This code in the forms unload event will ask the user if they want to close the form.
Code:
Private Sub Form_Unload(Cancel As Integer)
If MsgBox("Did you mean to close this form?", vbQuestion + vbYesNo, "Close Form?") = vbYes Then
'do nothing and let the form close
Else
Cancel = True
MsgBox "The form will not close."
End If
End Sub
The below code will disable (hide) all menu bars and tool bars.
Ensure that you have a way to enable (unhide) the menu bars
and tool bars (transparent command button) before you hide them!
'this will disable all menu bars and tool bars
Dim i As Integer
For i = 1 To CommandBars.Count
CommandBars(i).Enabled = False
Next i
'this will enable all menu bars and tool bars
Dim i As Integer
For i = 1 To CommandBars.Count
CommandBars(i).Enabled = True
Next i
'An added bonus is the right click option is disabled if the menu bars are disabled with the above code.
'Use the 'ShowToolbar' command if you need to display a tool bar or menu bar...
DoCmd.ShowToolbar "YourToolBarNameHere", acToolbarYes
'This will hide a tool bar or menu bar when needed...
DoCmd.ShowToolbar "YourToolBarNameHere", acToolbarNo
'This will hide the Menu Bar...
DoCmd.ShowToolbar "Menu Bar", acToolbarNo
'You can also hide/unhide the database window with code...
'Hide the database window
DoCmd.SelectObject acTable, , True
DoCmd.RunCommand acCmdWindowHide
'Unhide the database window
DoCmd.SelectObject acTable, , True
THANKS ghudson, The CANCEL statment did the trick. As for now i'm not hiding my db window because i'm making lots of changes everyday. I will use the above code when the time comes to hide it.