Save As and Control Box

When I close an application using the X in the control box, how do I bring up the Save As Common Dialog box?  I can do it with an Exit button, but not with the X.
jdn1640Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bob LearnedCommented:
Look at the QueryUnload event
0
Erick37Commented:
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    If UnloadMode = vbFormControlMenu Then
        Dim lRes As VbMsgBoxResult
        'The [X] button was pressed
        lRes = MsgBox("Really Quit?", vbQuestion Or vbYesNo, "Title")
        If lRes = vbNo Then Cancel = True
    End If
End Sub
0
fibdevCommented:
Erick37 told you strait, however if you wish to bring up a save box first ... Place a commonDialoge Control on your form and ...


Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    If UnloadMode = vbFormControlMenu Then
        Dim lRes As VbMsgBoxResult
        'The [X] button was pressed
        lRes = MsgBox("Really Quit?", vbQuestion Or vbYesNo, "Title")
        If lRes = vbNo Then Cancel = True
        If lRes = vbYes then
          CommonDialoge1.Filter = "All Files (*.*) | *.*"
          CommonDialoge1.ShowSave
        End
        End If
    End If
End Sub

Please forgive any syntax errors, it's late here :)

0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Erick37Commented:
Well, if the cancel is used then it should be:

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    If UnloadMode = vbFormControlMenu Then
        Dim lRes As VbMsgBoxResult
        'The [X] button was pressed
        lRes = MsgBox("Save Files?", vbQuestion Or vbYesNoCancel, "Title")
        Select Case lRes
        Case vbYes
            'Save your file(s)
            MsgBox "Bring up ""Save As"" box here"
        Case vbCancel
            'Cancel the unload
            Cancel = True
        End Select
    End If
End Sub
0
prem_kumar_25Commented:
Dear Friend

I hope that These simple lines can solve ur problem

Private Sub Form_Unload(Cancel As Integer)
CommonDialog1.ShowSave
End Sub

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mark2150Commented:
You want to *share* the same routine for both? Simpler yet. Assume your exit button is called BTN_EXIT then simply code:

Private Sub Form_Unload(Cancel As Integer)
If UnloadMode <> vbFormCode then Call Btn_Exit_Click
End Sub

This way you only need *ONE* copy of your service routine ...

M
0
GordonpCommented:
rather than call the button from the unload event, simply unload the form in the exit button and the Form_QueryUnload event will be called anyway

Private Sub cmdExit_Click()
    Unload Me
End Sub

Private Sub Form_Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
{
    'Do exit stuff here
}

Gordon
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.