[RESOLVED] Unload problem
Hi people, :)
I have trawled this forums topics and put together this which I hoped would become a 'one size fits all' piece of code. Problem is....when I cancel the unload from the 'X' button it works ok, but when I cancel the unload from the exit cmdbutton or menuexit it still unloads. Would you peeps be kind enough to have a look and give me some pointers?
Code:
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
On Error GoTo errorhandler
Dim frm As Form
Dim intPress As Integer
Select Case UnloadMode
Case vbFormControlMenu 'UnloadMode 0 'form is being unloaded via the Close or by hitting the X in the upper right hand corner command from the System menu
intPress = MsgBox("Are you sure you want to exit ? ", vbQuestion + vbOKCancel, "Exit Program")
If intPress <> vbOK Then
Cancel = -1
Exit Sub
Else
For Each frm In Forms
Unload frm
Next
End If
Case vbFormCode 'UnloadMode 1 - Unload Me has been issued from code
intPress = MsgBox("Are you sure you want to exit ? ", vbQuestion + vbOKCancel, "Exit Program")
If intPress = 2 Then
Cancel = -1
Exit Sub
Else
For Each frm In Forms
Unload frm
Next
End If
Case vbAppWindows 'UnloadMode 2
For Each frm In Forms
Unload frm
Next
Case vbAppTaskManager 'UnloadMode 3
For Each frm In Forms
Unload frm
Next
End Select
Exit Sub
errorhandler:
Number = Err.Number
Call Callerror(Number)
End Sub
Thankyou in anticipation.
regards
GB B)
Re: [RESOLVED] Unload problem
Glad I culd help. One suggestion I could make would be to change
Code:
intPress = MsgBox("Are you sure you want to exit ? ", vbQuestion + vbOKCancel, "Exit Program")
'to
intPress = MsgBox("Are you sure you want to exit ? ", vbQuestion + vbYesNo, "Exit Program") ' or vbYesNoCancel
Re: [RESOLVED] Unload problem
Well two suggestions :) Change
Code:
intPress = MsgBox("Are you sure you want to exit ? ", vbQuestion + vbOKCancel, "Exit Program")
If intPress <> vbOK Then
'to
If MsgBox("Are you sure you want to exit ? ", vbQuestion + vbOKCancel, "Exit Program") <> vbOK Then