This is one way to do it:
VB Code:
  1. Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
  2.    'see if the person used the X, pressed Alt+F4, or selected Close from the control menu
  3.    If UnloadMode = vbFormControlMenu Then
  4.       'if so, do your things here that you need to do
  5.  
  6.       'stop the unloading by giving Cancel a nonzero value
  7.       Cancel = True
  8.    End If
  9. End Sub