|
-
Apr 4th, 2006, 09:45 AM
#1
Thread Starter
Junior Member
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)
-
Apr 4th, 2006, 09:48 AM
#2
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
-
Apr 4th, 2006, 09:51 AM
#3
Fanatic Member
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
-
Apr 4th, 2006, 09:52 AM
#4
Re: Message boxes
 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.
-
Apr 4th, 2006, 09:53 AM
#5
Re: Message boxes
 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
-
Apr 4th, 2006, 10:03 AM
#6
Fanatic Member
Re: Message boxes
 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
-
Apr 4th, 2006, 10:07 AM
#7
Thread Starter
Junior Member
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?
-
Apr 4th, 2006, 10:08 AM
#8
Re: Message boxes
 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!
-
Apr 4th, 2006, 11:17 AM
#9
Re: Message boxes
 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
-
Apr 4th, 2006, 11:21 AM
#10
PowerPoster
Re: Message boxes
 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?
-
Apr 4th, 2006, 11:25 AM
#11
Re: Message boxes
 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.
-
Apr 4th, 2006, 11:28 AM
#12
Re: Message boxes
 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.
 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!
-
Apr 4th, 2006, 02:24 PM
#13
Thread Starter
Junior Member
Re: Message boxes
sorry to break up the discussion.. but why doesnt the unload me command work? read my post above. Thnaks
-
Apr 4th, 2006, 02:38 PM
#14
Fanatic Member
Re: Message boxes
Try doing a breakpoint on the bit where you unload it.
What are you trying to do before it unloads?
-
Apr 4th, 2006, 02:48 PM
#15
Re: Message boxes
 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.
-
Apr 4th, 2006, 04:00 PM
#16
Thread Starter
Junior Member
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.
-
Apr 4th, 2006, 04:02 PM
#17
Thread Starter
Junior Member
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.
-
Apr 4th, 2006, 04:21 PM
#18
Re: Message boxes
 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.
-
Apr 4th, 2006, 05:00 PM
#19
Thread Starter
Junior Member
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.
-
Apr 4th, 2006, 05:14 PM
#20
Re: Message boxes
Oh! You are in the wrong forum and so I've moved the thread for you.
-
Apr 4th, 2006, 05:34 PM
#21
Thread Starter
Junior Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|