Message box or Dialog, which to use

Posted on 2006-05-01
Last Modified: 2010-05-18
Hi experts,

I have a form that has multiple buttons, I need to ask the user a question, "Edit Mode or Add Mode", when the button is clicked.  Dependant on the users selection, will determine which form is opened.  What is the best way to accomplish this?  Examples please.

Question by:NCSO
    LVL 65

    Expert Comment

    by:Jim Horn
    If you need to have custom button captions, then msgbox will not work, and you'll need to use your own dialog form.
    LVL 37

    Expert Comment

    by:Harisha M G
    Hi, try this:

    Select Case MsgBox("Click Yes for Edit Mode, No for Add Mode or Cance to Cancel the action",vbYesNoCancel)
        Case vbYes:
            'Perform Edit Mode
        Case vbNo:
            'Perform Add Mode
        Case Else:
            'Do something else or nothing
    End Select

    LVL 76

    Expert Comment

    You would need to rephrase the question and if you want to use MsgBox.

    e.g. "Click 'Yes' for Edit mode and 'No' for Add Mode"
    LVL 13

    Expert Comment

    I am not trying to be a jerk here, but I think that Harish's suggestion is very counter-intuitive.  If you're going to have Yes or No buttons, the message box should be asking a Yes or No question.  Having to translate what Yes and No truly represent would be very tedious.  Just something to consider.

    Author Comment

    I truly just wanted, when the user clicks an object that some type of visual control asks if they want to "Add a New Record" or "Edit and Existing Record"
    LVL 52

    Accepted Solution

    If they're two seperate questions then a MsgBox will do fine:

        Private Sub cmdEdit_Click()
            If MsgBox("Edit record ?", vbYesNo) = vbYes Then
                '// Code to edit the record
            End If
        End If

        Private Sub cmdAdd_Click()
            If MsgBox("Add an new record ?", vbYesNo) = vbYes Then
                '// Code to edit the record
            End If
        End If

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    VBA - Excel progress bar 22 72
    Problem to the message 13 54
    vba find the last empty column 10 74
    Updates not working for MS Windows 7 12 82
    Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
    Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
    Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
    Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

    754 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

    Need Help in Real-Time?

    Connect with top rated Experts

    26 Experts available now in Live!

    Get 1:1 Help Now