MsgBox on exit from database

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

H

I hope that someone can help me. I am a complete novice with access but have somehow managed to created a database for our office. The problem i have is that one of my employees keeps exiting the database by accident (dont ask!). I would like to be able to add in some kind of warning/msg box with a yes or no option when someone exits the database

Trouble is it needs to be fairly simple as im only a beginner

Im using Access 97

Thanks in advance for your help

Caro
 
Hallo,

One of many ways to accomplish this ;-)

Simply paste the below code in the code part of the form Switchboard or form
that you made and use at startup. Click on the code icon (square icon with
yellow, blue parts and a star in top left and when moved over by mouse it
says code)

'code start
Private Sub Form_Unload(Cancel As Integer)
If MsgBox("Close?", vbYesNo + vbQuestion, "<Database name>") = vbNo Then
Cancel = True
DoCmd.CancelEvent
Debug.Print Forms.Count
Dim frmCount As Integer
frmCount = Forms.Count
Dim i As Integer
For i = (frmCount - 1) To 0 Step -1
' Print name of form.
Debug.Print "Form" & Forms(i).Name
' Enumerate Controls collection of each form.
If Not Forms(i) Is Me Then
Debug.Print "Not me is" & Forms(i).Name
DoCmd.Close acForm, Forms(i).Name, acSaveNo
End If
Next i
Dim rptCount As Integer
rptCount = Reports.Count
For i = (rptCount - 1) To 0 Step -1
DoCmd.Close acReport, Reports(i).Name, acSaveNo
Next i
End If
End Sub
'code end

Regards,
Harmannus


CarolM said:
Hi

I hope that someone can help me. I am a complete novice with access but
have somehow managed to created a database for our office. The problem i
have is that one of my employees keeps exiting the database by accident
(dont ask!). I would like to be able to add in some kind of warning/msg box
with a yes or no option when someone exits the database.
 
Back
Top