Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

programming msgbox.

Posted on 2006-06-14
8
Medium Priority
?
229 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
8 Comments
 
LVL 8

Accepted Solution

by:
List244 earned 2000 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses

721 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