Option Explicit
Public Function ConfirmExit(Optional Title As String = "Konfirmasi") As Boolean
If MsgBox("Are you sure want to exit?", vbQuestion + vbYesNo, Title) = vbYes Then
ConfirmExit = ConfirmExit
Else
ConfirmExit = True
End If
End Function
Contoh penggunaan fungsi di atas:
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Cancel = ConfirmExit
End Sub
Penggunaan fungsi di atas dapat kita tempatkan pada event Unload ataupun QueryUnload.