-
I have a saveas statement that seems to be forcing a program shutdown.
Anyone have any idea why this is happening?
You click exit, if you have not already saved then it asks you if you want to save, if you click yes it opens the saveas box, but if you now click cancel it shuts the whole program down- I have no idea why.....
Anyone have any ideas?
Dim saver as boolean
Private Sub mnuExit_Click()
Dim vbexpressions As Integer
Dim expression As String
Dim title As String
title = "Text Box"
'Set properties for a quit check, and check saver.
vbexpressions = vbQuestion + vbYesNo
expression = "Quit without saving?"
'If <> saved then double checks before closing.
If saver = False Then
response = MsgBox(expression, vbexpressions, title)
Select Case response
Case vbYes
End
Case vbNo
mnuSaveAs_Click
End Select
End If
End Sub
Private Sub mnuSaveAs_Click()
Dim Filter
On Error GoTo ErrHandler
Filter = "Text Files(*.text)|*.txt|"
Filter = Filter + "All Files (*.*)|*.*|"
CommonDialog1.Filter = Filter
'sets a default filter for Save As dialog box.
CommonDialog1.FilterIndex = 1
'sets the type of dialog box to be displayed.
CommonDialog1.Action = 2
'sets the path and filename of a selected file.
strName = CommonDialog1.FileName
Open strName For Output As #1
Print #1, TextBox1.Text
Close #1
'set saver
saver=true
ErrHandler:
End Sub
-
Try this:
Code:
Dim saver as boolean
Private Sub mnuExit_Click()
Unload Me
End Sub
Private Sub Form_Unload(Cancel As Integer)
Dim vbexpressions As Integer
Dim expression As String
Dim title As String
title = "Text Box"
'Set properties for a quit check, and check saver.
vbexpressions = vbQuestion + vbYesNo
expression = "Quit without saving?"
'If <> saved then double checks before closing.
If saver = False Then
response = MsgBox(expression, vbexpressions, title)
Select Case response
Case vbYes
End
Case vbNo
mnuSaveAs_Click
Cancel = True
End Select
End If
End Sub
Private Sub mnuSaveAs_Click()
Dim Filter
On Error GoTo ErrHandler
Filter = "Text Files(*.text)|*.txt|"
Filter = Filter + "All Files (*.*)|*.*|"
CommonDialog1.Filter = Filter
'sets a default filter for Save As dialog box.
CommonDialog1.FilterIndex = 1
'sets the type of dialog box to be displayed.
CommonDialog1.Action = 2
'sets the path and filename of a selected file.
strName = CommonDialog1.FileName
Open strName For Output As #1
Print #1, TextBox1.Text
Close #1
'set saver
saver=true
ErrHandler:
End Sub
-
Well, I don't know, I've used your code with MINOR modifications and it worked just fine.
Can you express your problem a little more clearly?
Code:
Option Explicit
Dim saver As Boolean
Private Sub mnuExit_Click()
Dim vbexpressions As Integer
Dim expression As String
Dim title As String
Dim response As Integer
title = "Text Box"
'Set properties for a quit check, and check saver.
vbexpressions = vbQuestion + vbYesNo
expression = "Quit without saving?"
'If <> saved then double checks before closing.
If saver = False Then
response = MsgBox(expression, vbexpressions, title)
Select Case response
Case vbYes
End
Case vbNo
mnuSaveAs_Click
End Select
End If
End Sub
Private Sub mnuSaveAs_Click()
Dim Filter, strName
On Error GoTo ErrHandler
Filter = "Text Files(*.txt)|*.txt|"
Filter = Filter + "All Files (*.*)|*.*|"
CommonDialog1.Filter = Filter
'sets a default filter for Save As dialog box.
CommonDialog1.FilterIndex = 1
'sets the type of dialog box to be displayed.
CommonDialog1.Action = 2
'sets the path and filename of a selected file.
strName = CommonDialog1.FileName
Open strName For Output As #1
Print #1, Text1.Text
Close #1
'set saver
saver = True
ErrHandler:
End Sub
-
Matthew, you don't need to put the "End" in the Unload event because it will unload anyway.
-
Perhaps Escaflowne, but I just re-copied bob323's code, showed him what he needed. It's also good to set your form to nothing as well so no resources from your program contine to be in use. (Set Form1 = Nothing)
Hope that helps, bob323.