×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

close program problem
2

close program problem

close program problem

(OP)
i have a question regarding visual basic close program porblem....
i have this code in the mnu...
a msg will be asked if any changed in file... but how do i link this to the left hand window corner "X- button"...so that, a msg will be asked too when i close the program from the "x-button"??

Public Sub mnuExit_Click()
If FileHasChanged = True Then

Style = vbYesNoCancel + vbQuestion
Response = MsgBox("Do you want to save this file?", Style)

If Response = vbYes Then
Call mnuSaveAs_Click
ElseIf Response = vbNo Then
End
UnloadAllForm
ElseIf Response = vbCancel Then
Exit Sub
End If
Else
End
UnloadAllForm
End If

End Sub

this is what will happen when i close the program from the "x-button"
1.)when i click the "x-button".. the Form that display on the MDIForm will invisible... and a msg "do you want to save the file?" will pop up...
2.)when i select "Yes"....a save dialog will pop up.. but once i select "Cancel" from the save dialog... the MDIForm will invisible...
3.)when i select cancel(from the msg).. the MDIForm will invisible also..

if i close the program from the file menu...it work fine..
hope you can follow..:)



besides, i have another question at here....
why all the comboboxes i have in the program will be highlighted? and how do i prevent this to happen??

RE: close program problem

(OP)
i have this in the form too..

Private Sub MDIForm1_Unload(Cancel As Integer)
mnuExit_Click
End Sub

this link the "x-button" to the mnuExit_Click...

RE: close program problem

Hi,

I don't know if the visual basic you have is the same as the one in word macros but this should work.

Private Sub UserForm_Terminate()
  
...Your Code or a Call to your sub (mnuExit_Click)

End Sub

Regards,

RE: close program problem

(OP)
i change it to this...but it doesn't work too....

Private Sub MDIForm_QueryUnload(Cancel As Integer, UnloadMode As Integer)
mnuExit_Click
End Sub

coz when i press the "cancel" from either msgbox.. or the save dialog.... the program will invisible...

plz help...:(

RE: close program problem

Hi Again,

My you get a lot of stars for asking questions !

Anyway, I've just tried this code (its not mine but microsofts) and it woks ok. Hope it works for you.
Private Sub Form_Unload(Cancel As Integer)
    Dim Msg, Response   ' Declare variables.
    Msg = "Save Data before closing?"
    Response = MsgBox(Msg, vbQuestion + vbYesNoCancel, "Save Dialog")
    Select Case Response
        Case vbCancel   ' Don't allow close.
            Cancel = -1
            Msg = "Command has been canceled."
        Case vbYes
        ' Enter code to save data here.
            Msg = "Data saved." '
        Case vbNo
            Msg = "Data not saved."
    End Select
    MsgBox Msg, vbOKOnly, "Confirm" ' Display message.
End Sub

Try it & See

Regards

RE: close program problem

(OP)
may i know.. what is the "stars" for?? the more stats mean what???
actually..i put the code in the wrong place...
i should do like this

Private Sub MDIForm_QueryUnload(Cancel As Integer, UnloadMode As Integer)
If FileHasChanged = True Then

Style = vbYesNoCancel + vbQuestion
Response = MsgBox("Do you want to save this file?", Style)

If Response = vbYes Then
Cancel = True
Call mnuSaveAs_Click

ElseIf Response = vbNo Then
End
UnloadAllForm
ElseIf Response = vbCancel Then
Cancel = True
Exit Sub
End If
Else
End
UnloadAllForm
End If

End Sub

Public Sub mnuExit_Click()
Unload Me
End If

RE: close program problem

I know it may seem like a cheats way out but if this is causing you too much trouble, try just disabling the
"x-Button". This way the user has to exit through your menu.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members! Already a Member? Login


Resources

Low-Volume Rapid Injection Molding With 3D Printed Molds
Learn methods and guidelines for using stereolithography (SLA) 3D printed molds in the injection molding process to lower costs and lead time. Discover how this hybrid manufacturing process enables on-demand mold fabrication to quickly produce small batches of thermoplastic parts. Download Now
Design for Additive Manufacturing (DfAM)
Examine how the principles of DfAM upend many of the long-standing rules around manufacturability - allowing engineers and designers to place a part’s function at the center of their design considerations. Download Now
Taking Control of Engineering Documents
This ebook covers tips for creating and managing workflows, security best practices and protection of intellectual property, Cloud vs. on-premise software solutions, CAD file management, compliance, and more. Download Now

Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close