Click to See Complete Forum and Search --> : Message boxes
Sinnie
Apr 4th, 2006, 09:45 AM
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)
baja_yu
Apr 4th, 2006, 09:48 AM
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
Darkbob
Apr 4th, 2006, 09:51 AM
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
Hack
Apr 4th, 2006, 09:52 AM
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.
baja_yu
Apr 4th, 2006, 09:53 AM
There's nothing wrong with the use of END
Don't say such a mean thing unless you post in Chit Chat :)
kregg
Apr 4th, 2006, 10:03 AM
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 :confused:
Sinnie
Apr 4th, 2006, 10:07 AM
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?
Hack
Apr 4th, 2006, 10:08 AM
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 :confused:Yes. All of that and a bag of donuts! :thumb:
MartinLiss
Apr 4th, 2006, 11:17 AM
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 :confused: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
BrailleSchool
Apr 4th, 2006, 11:21 AM
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?
MartinLiss
Apr 4th, 2006, 11:25 AM
...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.
Hack
Apr 4th, 2006, 11:28 AM
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.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! :thumb:
Sinnie
Apr 4th, 2006, 02:24 PM
sorry to break up the discussion.. but why doesnt the unload me command work? read my post above. Thnaks
kregg
Apr 4th, 2006, 02:38 PM
Try doing a breakpoint on the bit where you unload it.
What are you trying to do before it unloads?
MartinLiss
Apr 4th, 2006, 02:48 PM
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.
Sinnie
Apr 4th, 2006, 04:00 PM
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.
Sinnie
Apr 4th, 2006, 04:02 PM
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.
MartinLiss
Apr 4th, 2006, 04:21 PM
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.
Sinnie
Apr 4th, 2006, 05:00 PM
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.
MartinLiss
Apr 4th, 2006, 05:14 PM
Oh! You are in the wrong forum and so I've moved the thread for you.
Sinnie
Apr 4th, 2006, 05:34 PM
Oh, didnt see this.. wasnt sure where to put it and assumed that a generic Vb forum was a good idea...sorry
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.