[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1232
  • Last Modified:

vb6 exit program warning msgbox

hi all
please check my program

Private Sub MDIForm_Unload(Cancel As Integer)
Dim msg As VbMsgBoxResult
msg = MsgBox("are you sure you want to exit", vbYesNo)
If msg = vbYes Then
SetSplitterValue
End
End If

End Sub
actually i want to show the dialog box when user click on the close button
if he press no then program should not close but when i click on the no button it is closing
what should i do
0
mubbsher
Asked:
mubbsher
  • 3
  • 3
  • 2
  • +5
1 Solution
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:

Private Sub MDIForm_QueryUnload(UnloadMode as Integer, Cancel As Integer)
Dim msg As VbMsgBoxResult
msg = MsgBox("are you sure you want to exit", vbYesNo)
If msg = vbYes Then
  SetSplitterValue
else
  cancel = true
End
End If
0
 
[ fanpages ]IT Services ConsultantCommented:
Try this:

Private Sub MDIForm_Unload(Cancel As Integer)
Dim msg As VbMsgBoxResult
msg = MsgBox("are you sure you want to exit", vbYesNo)
If msg = vbYes Then
SetSplitterValue
Else
   Cancel = True
End
End If

'

BFN,

fp.
0
 
[ fanpages ]IT Services ConsultantCommented:
Or even...

Private Sub MDIForm_Unload(Cancel As Integer)
Dim msg As VbMsgBoxResult
msg = MsgBox("are you sure you want to exit", vbYesNo)
If msg = vbYes Then
SetSplitterValue
End
Else
   Cancel = True
End If


(Moved the "End" statement inside the If msg = vbYes branch)

BFN,

fp.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
Well, END should not be used at all... as this closes the application the "hard way"

Private Sub MDIForm_QueryUnload(UnloadMode as Integer, Cancel As Integer)
Dim msg As VbMsgBoxResult
msg = MsgBox("are you sure you want to exit", vbYesNo)
If msg = vbYes Then
  SetSplitterValue
else
  cancel = true
End If

End Sub
0
 
mubbsherAuthor Commented:
i use your code but it still closing on
i m using mdi form
0
 
[ fanpages ]IT Services ConsultantCommented:
Not sure what you were tryng to say, or which code you tried, but have a go at this:

Private Sub MDIForm_QueryUnload(UnloadMode as Integer, Cancel As Integer)

If MsgBox("are you sure you want to exit", vbYesNo Or vbQuestion) = vbNo Then
   Cancel = True
   Exit Sub
End If

SetSplitterValue

End Sub


BFN,

fp.
0
 
nffvrxqgrcfqvvcCommented:
Dim MBOX As Long
   
    MBOX = MsgBox("are you sure you want to exit", vbYesNo)
   
    Select Case MBOX
        Case vbYes
            'exit normally
        Case vbNo
            Cancel = True
    End Select
0
 
lunchbyteCommented:
You may have overlooked which procedure to use. Make sure it is QueryUnload as indicated in above samples and you may still be using Unload procedure.
0
 
deightonCommented:
is End all bad?
0
 
lunchbyteCommented:
deighton, maybe you should open your own post with that question because you are hijacking the thread now. LOL.

I wanted to response to it anyway. End should be used as a last resort because if you end it, nothing gets fired and the program completely shuts down. So if you had certain things that need to be done in unload event, recordset or variables that needs to be clear before you close it, all that will be ignored. I used it when the program runs into major problem and I want it to shut down without going through any event or procedure.

0
 
hi12345Commented:
Put the code in query unload:

private sub Form_QueryUnLoad()
      if msgbox("do you want to exit?", vbQuestion or vbYesno, "Exit?") = vbYes then
              ' exit the program
      else
              ' don't exit the program
              cancel = 1
      endif
end sub

This works perfectly.
- hi12345
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
>This works perfectly.
except that you forgot to put the parameter definitions of the QueryUnload event
Also, the usage of the Cancel Parameter to be set to true has been suggested several times in this thread already :-)
0
 
lalitgadaCommented:
Private Sub MDIForm_QueryUnload(UnloadMode as Integer, Cancel As Integer)
Dim msg As VbMsgBoxResult
msg = MsgBox("are you sure you want to exit", vbYesNo)
If msg = vbYes Then
  SetSplitterValue
End
else
  cancel = true
End
End If
0
 
lalitgadaCommented:
Use the END after SetSplitterValue and not after cancel=true
if you use cancel=true in the else part the form will not get closed.

Private Sub MDIForm_QueryUnload(UnloadMode as Integer, Cancel As Integer)
Dim msg As VbMsgBoxResult
msg = MsgBox("are you sure you want to exit", vbYesNo)
If msg = vbYes Then
  SetSplitterValue
  End
else
  cancel = true
End If
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 3
  • 3
  • 2
  • +5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now