WorkingVBA
Registered User.
- Local time
- Yesterday, 18:13
- Joined
- Jul 3, 2013
- Messages
- 33
Hi,
I found this code in the forum to confirm closing the database. For some reason it works fine the first time around if you close MS Access by clicking the X (i.e. the quit is canceled), but if you do it again it goes ahead and closes anyways. Anyone know what is happening?
Thanks for your help
I found this code in the forum to confirm closing the database. For some reason it works fine the first time around if you close MS Access by clicking the X (i.e. the quit is canceled), but if you do it again it goes ahead and closes anyways. Anyone know what is happening?
Thanks for your help
Code:
Private Sub Form_Unload(Cancel As Integer)
Dim varResp As Variant
' this sub closes the program while leaving Access open
On Error GoTo err_handler
varResp = MsgBox("If you want to EXIT Access completely, press YES. " & vbCrLf & _
"If you want to CLOSE the program while leaving Access open, press NO." & vbCrLf & _
"If you want to CANCEL and go back to the program, press CANCEL.", vbYesNoCancel, "Close Confirmation")
Select Case varResp
Case vbYes
DoCmd.Quit
Case vbNo
CloseCurrentDatabase
Case vbCancel
Cancel = True
Exit Sub
End Select
Exit Sub
err_handler:
If Err.Number = 2763 Then
Exit Sub
Else
If MsgBox(Err.Description & vbCrLf & "Do you wish to continue?", vbCritical + vbYesNo + vbDefaultButton1, "Error number: " & Err.Number) = vbYes Then
Resume Next
Else
Exit Sub
End If
End If
End Sub