Handling The Close [x] Button Of A Form

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Kabyr
    New Member
    • Nov 2007
    • 29

    Handling The Close [x] Button Of A Form

    Hi everyone,
    Can someone help me with a procedure to handle the clicked event of the Close button (The [X] button on the top right coner of a VB form. I want to be able to query the users intention for clicking, like: Does he want to save before closing ... instead of just closing the window.

    I used a command button to achieve this but I also want to do same for the Close button.
  • numberwhun
    Recognized Expert Moderator Specialist
    • May 2007
    • 3467

    #2
    Originally posted by Kabyr
    Hi everyone,
    Can someone help me with a procedure to handle the clicked event of the Close button (The [X] button on the top right coner of a VB form. I want to be able to query the users intention for clicking, like: Does he want to save before closing ... instead of just closing the window.

    I used a command button to achieve this but I also want to do same for the Close button.
    Please, DO NOT post questions in the Member Introductions Forum. Heck, there is even a thread with a title asking you not to.

    I am moving this question to the VB forum.

    Regards,

    Jeff

    Comment

    • Mohan Krishna
      New Member
      • Oct 2007
      • 115

      #3
      Originally posted by Kabyr
      Hi everyone,
      Can someone help me with a procedure to handle the clicked event of the Close button (The [X] button on the top right coner of a VB form. I want to be able to query the users intention for clicking, like: Does he want to save before closing ... instead of just closing the window.

      I used a command button to achieve this but I also want to do same for the Close button.
      Hi
      Try...
      Code:
      Private Sub Form_Terminate()
          MsgBox "Hai"
      End Sub
      ALL THE BEST!
      respond is it helpful...

      Comment

      • Killer42
        Recognized Expert Expert
        • Oct 2006
        • 8429

        #4
        The details will depend on what version of VB you're using.

        In VB6 you would use the form's QueryUnload and/or Unload events.

        Comment

        • lotus18
          Contributor
          • Nov 2007
          • 865

          #5
          Originally posted by Killer42
          The details will depend on what version of VB you're using.

          In VB6 you would use the form's QueryUnload and/or Unload events.
          But it depends on the form and/or type of application. Let us say for an instance we have 1 form and containing all the list of any record, then when adding/modifying a particular record we're using another form and it is shown as vbmodal. What if the user add new record, how can you unload that form without prompting a message box? : )

          Rey Sean

          Comment

          • Killer42
            Recognized Expert Expert
            • Oct 2006
            • 8429

            #6
            Originally posted by lotus18
            But it depends on the form and type of application. Let us say for an instance we have 1 form and containing all the list of any record, then when adding/modifying a particular record we're using another form and it is shown as vbmodal. What if the user add new record, how can you unload that form without prompting a message box? : )
            Seems to me, that's way off-topic for this thread. We're dealing with kind of the oposite - what to do when the user clicks Close.

            You probably should start a new discussion for your question, including as much detail as possible about the situation.

            Comment

            • lotus18
              Contributor
              • Nov 2007
              • 865

              #7
              Hi Killer42

              I was only just gave my opinion and it was relevant to the topic. I'll post that question soon : )

              Rey Sean

              Comment

              • Mohan Krishna
                New Member
                • Oct 2007
                • 115

                #8
                Hi Killer and Lotus,

                Very good discussion!
                Here we can use any of the above Form Events.
                But as Lotus raised a question, it makes some problem when another form is shown MODAL. Please Lotus post a new thread and we try to get a solution.

                But where is Kabyr whether he got the solution from this good discussion.
                Thank you both of you!

                This is my 100th post.

                Thank You ALL!

                Comment

                • lotus18
                  Contributor
                  • Nov 2007
                  • 865

                  #9
                  Originally posted by Mohan Krishna
                  Hi Killer and Lotus,

                  Very good discussion!
                  Here we can use any of the above Form Events.
                  But as Lotus raised a question, it makes some problem when another form is shown MODAL. Please Lotus post a new thread and we try to get a solution.

                  But where is Kabyr whether he got the solution from this good discussion.
                  Thank you both of you!

                  This is my 100th post.

                  Thank You ALL!
                  Hi Mohan

                  Congrats for your 100th post. haha...

                  I think Kabyr got the solution from this forum. OK, I'll post the question later, I have some work out here. lol : )

                  Rey Sean

                  Comment

                  • 9815402440
                    New Member
                    • Oct 2007
                    • 180

                    #10
                    hi

                    use following code

                    Private Sub Form_Unload(Can cel As Integer)
                    If MsgBox("do you want to close this form", vbYesNo) = vbNo Then
                    Cancel = 1
                    End If
                    End Sub

                    regards
                    manpreet singh dhillon hoshiarpur

                    Comment

                    • Mohan Krishna
                      New Member
                      • Oct 2007
                      • 115

                      #11
                      Originally posted by lotus18
                      Hi Mohan

                      Congrats for your 100th post. haha...

                      ...lol : )

                      Rey Sean
                      Thank You Lotus!
                      This is a very good and quick responsive forum!

                      Comment

                      • lotus18
                        Contributor
                        • Nov 2007
                        • 865

                        #12
                        Originally posted by Mohan Krishna
                        Thank You Lotus!
                        This is a very good and quick responsive forum!
                        Hello Mohan

                        I've just posted the question as you requested : )
                        As you've said, this will gonna be interesting lol (haha)

                        Rey Sean

                        Comment

                        • Kabyr
                          New Member
                          • Nov 2007
                          • 29

                          #13
                          Thanks everyone!!!!!!! !!!!!!!!!!!!!!! !!!!!!!!!
                          Form_Unload did the job.

                          You made my day.
                          Last edited by Killer42; Dec 13 '07, 12:44 AM.

                          Comment

                          • Killer42
                            Recognized Expert Expert
                            • Oct 2006
                            • 8429

                            #14
                            Glad we could help. :)

                            Comment

                            Working...