|
-
Jul 17th, 2000, 10:03 PM
#1
Thread Starter
Addicted Member
Ok I've made this work before but can't get it to do it this time. When the user hits X on the form the user is aske if he/she wants to save changes yes and no work fine but the form still unloads if you hit cancel...
code:
Private Sub Form_Unload(Cancel As Integer)
If NoteDirty Then
Dim z
z = MsgBox("Would you like to save changes?", vbYesNoCancel, "Save changes?")
If z = 6 Then
mnuFileSave_Click
ElseIf z = 2 Then
Exit Sub
Else
'oh well
End If
End If
End Sub
Its a replacement for notepad since mine is screwed for some reason....
Thankz
Magiaus
Visual Basic 6.0 SP5
Visual C++ 6.0 SP5
The only sovereign you can allow to rule you is reason.
-
Jul 17th, 2000, 10:23 PM
#2
Addicted Member
try
Code:
msgbox "need to save it ?", vboksavecancel,"save"
if vbok = true then
savefile
elseif
exit
else
end if
off the top of my head , so if it dont work sorry
WHat would we do with out Microsoft.
A lot more.
-
Jul 17th, 2000, 10:29 PM
#3
Hyperactive Member
Cancel = 1
You gotta set the Cancel variable to make sure the program understands you're canceling the unload.
like this
Code:
Private Sub Form_Unload(Cancel As Integer)
If NoteDirty Then
Dim z
z = MsgBox("Would you like to save changes?", vbYesNoCancel, "Save changes?")
If z = 6 Then
mnuFileSave_Click
ElseIf z = 2 Then
Exit Sub
Else
'oh well
Cancel = 1 ' <---------
End If
End If
End Sub
Signed, Rodik ([email protected])
Programmer,usesVB6ED
===========================
Copyright©RodikCo,2002.
Dont mind this signature ;] Its old
-
Jul 19th, 2000, 12:41 AM
#4
Lively Member
Right Idea, just the wrong event. Use the queryunload event of the form.
Code:
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Dim lResult As Long
If UnloadMode = vbFormControlMenu Then
lResult = MsgBox("Would you like to save changes?", vbYesNoCancel, "Save changes?")
Select Case lResult
Case vbYes
'Do save here
Case vbNo
'Just let it exit anyway
Case vbCancel
'Dont close
Cancel = True
End Select
End If
End Sub
-
Jul 19th, 2000, 12:54 AM
#5
Thread Starter
Addicted Member
THankz Guys
But why is it better to use Form_QuerryUnload?
Magiaus
Visual Basic 6.0 SP5
Visual C++ 6.0 SP5
The only sovereign you can allow to rule you is reason.
-
Jul 19th, 2000, 01:17 AM
#6
Lively Member
With the query unload event you can tell how your program is being unloaded.
-
Jul 19th, 2000, 01:41 AM
#7
Hyperactive Member
True, but with the sample code ("If UnloadMode = vbFormControlMenu Then") you only ask to save changes when the user presses the X-button, but when windooz stops (or the program is closed thru the taskmanager) it won't be asked, so in this case it doesn't really matter whether to use the query_unload or the unload event, you always want to save changes.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|