how can I prevetn a user from closing an Access document by clicking on the uper right hand side X button?
An Access database isn't really a "document" - it's a container for
multiple forms, tables, reports and other objects.
To block closing a Database prematurely, you must open a Form (you can
then make it invisible if you wish) when the database opens. Put VBA
code in that Form's Close event to check whether a condition has been
set to allow closing, and Cancel the close event if not.
For example, you could define a Global Variable:
Public bOKToClose As Boolean
In the code for whatever event you want to close the database (a
button click for instance) set this variable to True. In the "trap"
form you'ld have code like
Private Sub Form_Close(Cancel as Integer)
If Not bOKToClose Then
MsgBox "Please close the application using the button"
Cancel = True
End If
End Sub
Be sure not to make it *too* difficult for the user to close -
otherwise they may get frustrated and ctrl-alt-delete and kill the
program, which can corrupt your database!