Results 1 to 6 of 6

Thread: Msgbox

  1. #1
    Join Date
    Sep 2005

    Unanswered: Msgbox

    In MS Access,

    MsgBox "Are you sure", vbOKCancel

    and there is OK , and Cancel buttons.

    I want to do that if click "OK", then run the action, if click "Cancel", then cancel the action.

    MsgBox "Are you sure", vbYesNo
    If (vbYesNo = 1) Then
    MsgBox "Yes"
    End If

    So, how do I edit it?

    Last edited by accessman2; 11-14-05 at 20:05.

  2. #2
    Join Date
    Nov 2004
    out on a limb
    Provided Answers: 59
    straight from the Access help system

    Response = MsgBox(Msg, Style, Title, Help, Ctxt)
    If Response = vbYes Then ' User chose Yes.
    MyString = "Yes" ' Perform some action.
    Else ' User chose No.
    MyString = "No" ' Perform some action.
    End If

    search for msgbox in the help system and you will also discover the values that equate to yes, no, cancel etc.

  3. #3
    Join Date
    Dec 2004
    Madison, WI


    FYI: 6 = yes, 7 = no. You can use numbers.
    If Response = 6 then....

    I'm not sure if you need to Dim the Response field. If you are, I believe we do it with Dim Response = integer. You may also get an error if the user just clicks cancel with no value. heraldem may do it different but I usually add in an on error goto done and the put the done label (i.e done with a colon after it : ) at the end of the statements.
    Last edited by pkstormy; 11-15-05 at 13:55.
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  4. #4
    Join Date
    Mar 2003
    The Bottom of The Barrel
    Provided Answers: 1
    Named constants tend to be returned as Longs... ancillory point granted, just sayin..

    Also, cut to the chase and lower your overhead:

    If msgbox("stuff", vbyesno) = vbYes Then
    Do stuff
    End If
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

  5. #5
    Join Date
    Apr 2004
    outside the rim
    FYI: 6 = yes, 7 = no. You can use numbers.
    You may want to avoid using numbers when VB provides a named constant - you never know when Microshaft will decide to change the values of some of their named constants, making cross-version software a problem.

    Besides - it'll make your code much more readable.

    just my opinion!

    oh, and you do have to DIM Response (Response is a variable name in the help file example) if you have Option Explicit in your code.

    Last edited by tcace; 11-15-05 at 16:54.

  6. #6
    Join Date
    Feb 2004
    Chicago, IL
    If you are using an OK/Cancel msgbox you will want to check those constants.

    MsgBox "Are you sure", vbYesNo
    If (vbYesNo = 1) Then
    MsgBox "Yes"
    End If


    Dim intResponse as Integer
    intResponse = MsgBox("Are you sure?",vbOkCancel)
    If intResponse = vbOK Then
         'Do Something
         'Do Something Else
    End If
    And I second the vote for using the Access constants. It is self documenting. As a matter of fact I will create my own named constants to help readability.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts