Solved

programming msgbox.

Posted on 2006-06-14
8
225 Views
Last Modified: 2010-04-07
How can I program YES, NO and CANCEL button on msgbox statement.

I want the msgbox statement to pop up when user presses delete(a button on my form)..the pop up screen should have three buttons, YES, NO and CANCEL..different codes should be executed be each one..

Thank you.
0
Comment
Question by:Aiysha
  • 4
  • 2
  • 2
8 Comments
 
LVL 8

Accepted Solution

by:
List244 earned 500 total points
ID: 16905452
Dim Result As Integer
Result = MsgBox("MESSAGE", vbYesNoCancel, "TITLE")
If Result = vbYes Then
    MsgBox "Yes"
Else
If Result = vbNo Then
    MsgBox "No"
Else
If Result = vbCancel Then
    MsgBox "Cancel"
End If
End If
End If
0
 
LVL 8

Expert Comment

by:List244
ID: 16905457
Then where I put : MsgBox "Yes" MsgBox "No" and MsgBox "Cancel" you would of course erase that and put the code you want
to take action in those areas.
0
 
LVL 8

Expert Comment

by:List244
ID: 16905471
Another approach would be using a select statement:

Select Case MsgBox("MESSAGE", vbYesNoCancel, "TITLE")
    Case vbYes
        MsgBox "Yes"
    Case vbNo
        MsgBox "No"
    Case vbCancel
        MsgBox "Cancel"
End Select
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 13

Expert Comment

by:Mark_FreeSoftware
ID: 16905488
Dim ret As Long
ret = MsgBox("are you sure you want to delete this file", vbYesNoCancel, "sure?")
If ret = vbYes Then
   'user clicked Yes
ElseIf ret = vbNo Then
   'user clicked no
ElseIf ret = vbCancel Then
   'user clicked cancel
End If

0
 
LVL 13

Expert Comment

by:Mark_FreeSoftware
ID: 16905496

List244 you beat me to it ;)

i had to press f5 before submitting :(
0
 
LVL 10

Expert Comment

by:fostejo
ID: 16906283
Aiysha,

You might also want to have a look at MZ-Tools 3.0 freeware available at http://www.mztools.com/v3/mztools3.htm

This add in to VB6 has a nice 'MsgBox Assistant' which allows you to 'pick and choose' the combination of buttons, icons and other settings you want. You can then preview it to make sure all's ok, prior to generating the required code to support the MsgBox.

(Plus it's got a load of other useful features also, such as Code Review, templates etc.)

cheers,
0
 
LVL 8

Expert Comment

by:List244
ID: 16906324
Aiysha, with all honesty, I do not believe you should go about using that, at least not for message boxes.  Tools that help us
get things done are great.  But message boxes are so simple that you would in my opinion cause yourself nothing but harm
by using such a tool.  It creates a tendency to be lazy much like copy-pasting.  I believe as a beginner to a language you should
practice as much as you can to learn what you can do.  As a beginner taking shortcuts is really not the way to go.  After you
learn and understand concepts, if you are trying to get something done, that is when you should use shortcuts, yet even then
do so carefully.
0
 
LVL 10

Expert Comment

by:fostejo
ID: 16907285
Aiysha,

Although I posted the comment, I do also agree with List244 !!

However, in my defence ;), tools like that 'create' some well structured and working code and allow you to explore the various options available to you that you might have never otherwise considered or 'bumped into' - in this instance, you can 'preview' what's going to the created and then pick apart *how* it does what it does from the code itself.

cheers!
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question