Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Save Reminder before exiting 1

Status
Not open for further replies.

klornpallier

Technical User
Aug 28, 2002
98
0
0
GB
I have a exit button with the code:

Private Sub CmdExit_Click()
Dim ExitQuestion As String
ExitQuestion = MsgBox("Have you saved your Schedule before Exiting?", vbYesNo, "Exit Scheduling Form")
If vbYes Then
End
Else
Exit Sub
End If
End Sub

If vbNo is selected I want the load to stay loaded but this code doesnt seem to work. Help
 
You should be using

Code:
If ExitQuestion = vbYes Then
    End
End If
 
Sorry to have responded so late.

Another option would be to ask if the client wants to save the data in the form's QueryUnload event. Here's a rough code sample.

Code:
'*****************************************************'
'DESCRIPTION:  (generated by VB)
' Before exiting, see if the client wants to save 
' their Schedule.
'*****************************************************'
Private Sub Form_QueryUnload(Cancel As Integer, _
    UnloadMode As Integer)

    Dim intNeedToSave As Integer

    NeedToSave = MsgBox("Do you want to save your Schedule?", _
            vbQuestion + vbYesNoCancel, "Save Schedule?")

    Select Case NeedToSave

        Case vbCancel   ' Return to original state and 
                        ' do not unload form.
            Cancel = vbYes

        Case vbYes      ' Client wants to save the Schedule

            'Call -your save Schedule procedure/logic here-

        Case vbNo       ' Client doesn't want to save the Schedule

    End Select

End Sub
 
As a general point, I'd tend to steer clear of 'End' if possible.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top