Results 1 to 21 of 21

Thread: Message boxes

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Dec 2005
    Posts
    17

    Message boxes

    Quite simple, im sure I should know the answer to this, but I cant put my finger on it

    I have this so far:



    Dim response As Integer

    Private Sub Command9_Click()
    response = MsgBox("Are you sure you want to quit?", vbQuestion + vbYesNo)
    If response = vbYes Then
    End
    Else
    End If

    End Sub



    So far all it does it close the message box whatever I press, I know that the 'end' is wrong, but am not sure what to change it to. I just want 'no' to go back to the form and 'Yes' to quit the application. (I am using Access with VBA)

  2. #2
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    Re: Message boxes

    use Unload Me. And you dont have to dim a variable simply do

    If MsgBox("Blah Blah Blah?", vbQuestion + vbYesNo) = vbYes Then
    Unload Me
    End If

  3. #3
    Fanatic Member
    Join Date
    Oct 2005
    Posts
    586

    Re: Message boxes

    The code you have posted works fine. You say YES and the application terminates. There's nothing wrong with the use of END and your MsgBox seems to work fine too.

    I wonder if you might have done something wrong when you defined the variable "Response"?

    Try running the code in debug mode and stepping through it line by line. Check the values as you go. It should work fine.

    --DB

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Message boxes

    Quote Originally Posted by Darkbob
    There's nothing wrong with the use of END and your MsgBox seems to work fine too.
    Bite your tongue.

    END should never, ever, ever, ever be used, not even if your printer just burst into flames.

  5. #5
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    Re: Message boxes

    Quote Originally Posted by Darkbob
    There's nothing wrong with the use of END
    Don't say such a mean thing unless you post in Chit Chat

  6. #6
    Fanatic Member kregg's Avatar
    Join Date
    Feb 2006
    Location
    UK
    Posts
    524

    Re: Message boxes

    Quote Originally Posted by Hack
    END should never, ever, ever, ever be used, not even if your printer just burst into flames.
    Whats so bad about the end command? Is it becuase that it just stops the thing right in the middle of what it was doing unlike Unload Me which allows it to unload itself from memory then terminate itself or something like that

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Dec 2005
    Posts
    17

    Re: Message boxes

    I put the unload me command in and it said it can't 'unload this object' I assume I need to replace 'me' with the object and i have tried Access (as that what I want to close), and the form name neither works, I usualy get a 'type mismatch'

    any ideas?

  8. #8
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Message boxes

    Quote Originally Posted by kregg
    Whats so bad about the end command? Is it becuase that it just stops the thing right in the middle of what it was doing unlike Unload Me which allows it to unload itself from memory then terminate itself or something like that
    Yes. All of that and a bag of donuts!

  9. #9
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Message boxes

    Quote Originally Posted by kregg
    Whats so bad about the end command? Is it becuase that it just stops the thing right in the middle of what it was doing unlike Unload Me which allows it to unload itself from memory then terminate itself or something like that
    To paraphrase something that Joacim Andersson once said, the difference between using Unload Me and using End is like the difference of asking a guest to leave your home and to throw him of the balcony and let him fall the 25 floors there are between your penthouse apartment and the street. In the first case (if he acts politely as any guest should do) he will pick up his things and take him and his entourage and leave, while in the second you kill him while his entourage and baggage is still in your home

  10. #10
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Re: Message boxes

    Quote Originally Posted by MartinLiss
    To paraphrase something that Joacim Andersson once said, the difference between using Unload Me and using End is like the difference of asking a guest to leave your home and to throw him of the balcony and let him fall the 25 floors there are between your penthouse apartment and the street. In the first case (if he acts politely as any guest should do) he will pick up his things and take him and his entourage and leave, while in the second you kill him while his entourage and baggage is still in your home
    question for all you guys. if you shouldnt use end, then why did MS have it available for use I wonder? i have, in the past, used unload me and then used end right afterward. bad idea?

  11. #11
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Message boxes

    Quote Originally Posted by BrailleSchool
    ...i have, in the past, used unload me and then used end right afterward. bad idea?
    I also used to do that but after several long discussions I was convinced that it wasn't necessary.

  12. #12
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Message boxes

    Quote Originally Posted by BrailleSchool
    question for all you guys. if you shouldnt use end, then why did MS have it available for use I wonder?
    That is a very good question for which I do not have a very good answer. The only thing I can think of is in the old, interpretive, of GWBasic and IBMBasic, End was used to stop the program. But, in the DOS days, there really wasn't anything to unload or destroy. Many features of the old DOS based Basic made its way into VB. Some things shouldn't have.
    Quote Originally Posted by BrailleSchool
    i have, in the past, used unload me and then used end right afterward. bad idea?
    If you have used Unload Me then (hopefully), all of the housekeeping has been done, so in this instance I wouldn't call it bad, but I would call it completely unnecessary, and I would further call it a practice that I would break myself of lest you mistakenly use it sometime without the Unload Me.

    PS: I love the Joacim example!

  13. #13

    Thread Starter
    Junior Member
    Join Date
    Dec 2005
    Posts
    17

    Re: Message boxes

    sorry to break up the discussion.. but why doesnt the unload me command work? read my post above. Thnaks

  14. #14
    Fanatic Member kregg's Avatar
    Join Date
    Feb 2006
    Location
    UK
    Posts
    524

    Re: Message boxes

    Try doing a breakpoint on the bit where you unload it.

    What are you trying to do before it unloads?

  15. #15
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Message boxes

    Quote Originally Posted by Sinnie
    I put the unload me command in and it said it can't 'unload this object' I assume I need to replace 'me' with the object and i have tried Access (as that what I want to close), and the form name neither works, I usualy get a 'type mismatch'

    any ideas?
    Please show your code.

  16. #16

    Thread Starter
    Junior Member
    Join Date
    Dec 2005
    Posts
    17

    Re: Message boxes

    Private Sub Command9_Click()
    If MsgBox("Do you want to quit?", vbQuestion + vbYesNo) = vbYes Then
    Unload Me
    End If

    End Sub


    simply as baja yu posted... I tried changing 'Me' to 'Access' and the forms name. As you can see im a novice to VB, and while I understand what Unload Me does, im not sure where and how to use it.

  17. #17

    Thread Starter
    Junior Member
    Join Date
    Dec 2005
    Posts
    17

    Re: Message boxes

    using breakpoints I get an error at the 'Unload me' line

    "Cant load or unload this object" which is where I assume 'Me' needs to be the actual object.

  18. #18
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Message boxes

    Quote Originally Posted by Sinnie
    Private Sub Command9_Click()
    If MsgBox("Do you want to quit?", vbQuestion + vbYesNo) = vbYes Then
    Unload Me
    End If

    End Sub


    simply as baja yu posted... I tried changing 'Me' to 'Access' and the forms name. As you can see im a novice to VB, and while I understand what Unload Me does, im not sure where and how to use it.
    There is nothing wrong with that code. If you zip up and attach your project I'll take a look at it.

  19. #19

    Thread Starter
    Junior Member
    Join Date
    Dec 2005
    Posts
    17

    Re: Message boxes

    That is the project as far as VB is concerned.. Im using Access, which makes me wonder if maybe the code needs to be changed.

    This is the code for when the user clicks quit, I could use a form and have command buttons do it but this way is much cleaner.

    I can zip up the database if you want, but will have to wait till later tomorrow.

  20. #20

  21. #21

    Thread Starter
    Junior Member
    Join Date
    Dec 2005
    Posts
    17

    Re: Message boxes

    Oh, didnt see this.. wasnt sure where to put it and assumed that a generic Vb forum was a good idea...sorry

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width