Msgbox cancel button

Discussion in 'Microsoft Access Forms' started by stoehrkr@gmail.com, Jun 15, 2007.

  1. Guest

    Hello!

    I'm fairly new to Access and VB and I've been getting along alright
    but I've run into a problem with a message box I set up in my form.

    Situation: the field FvsNF will always be filled out. Depending on
    the answer (yes or no) certain fields become enabled or disabled. The
    problem is if a user decides to change their answer for FvsNF after
    filling out the wrong fields. The incorrect fields need to go back to
    zero if they decide to proceed with that action. However if they
    don't want to proceed I want to give them an out without losing their
    entries. The code I have now is:

    Private Sub FvsNF_BeforeUpdate(Cancel As Integer)
    Result = MsgBox("Warning: All values in section will become zero.",
    vbOKCancel)
    If vbOK Then
    TotalCC.Value = 0
    OSCC.Value = 0
    Clumpiness.Value = 0
    ClumpDensity.Value = 0
    ClumpSize.Value = 0
    CrownDiff.Value = 0
    CanopyLayers.Value = 0
    Logging.Value = 0
    pcc.Value = 0
    DensOS.Value = -99
    DensUS.Value = -99
    sizeOS.Value = 0
    sizeUS.Value = 0
    sppOS.Value = 0
    sppUS.Value = 0
    Nonforesttype.Value = 0
    ElevBelt.Value = 0
    nonforestsppOS.Value = 0
    nonforestOSCC.Value = 0
    treecovergstype.Value = 0
    Else

    End If
    End Sub

    I've tried a lot of things under Else...and lots of different
    combinations but I can't seem to get the cancel button to cancel! Any
    help would be greatly appreciated!

    Kali
     
    , Jun 15, 2007
    #1
    1. Advertisements

  2. Me.UnDo will return all of the controls to the values last saved.

    wrote:
    >Hello!
    >
    >I'm fairly new to Access and VB and I've been getting along alright
    >but I've run into a problem with a message box I set up in my form.
    >
    >Situation: the field FvsNF will always be filled out. Depending on
    >the answer (yes or no) certain fields become enabled or disabled. The
    >problem is if a user decides to change their answer for FvsNF after
    >filling out the wrong fields. The incorrect fields need to go back to
    >zero if they decide to proceed with that action. However if they
    >don't want to proceed I want to give them an out without losing their
    >entries. The code I have now is:
    >
    >Private Sub FvsNF_BeforeUpdate(Cancel As Integer)
    >Result = MsgBox("Warning: All values in section will become zero.",
    >vbOKCancel)
    > If vbOK Then
    > TotalCC.Value = 0
    > OSCC.Value = 0
    > Clumpiness.Value = 0
    > ClumpDensity.Value = 0
    > ClumpSize.Value = 0
    > CrownDiff.Value = 0
    > CanopyLayers.Value = 0
    > Logging.Value = 0
    > pcc.Value = 0
    > DensOS.Value = -99
    > DensUS.Value = -99
    > sizeOS.Value = 0
    > sizeUS.Value = 0
    > sppOS.Value = 0
    > sppUS.Value = 0
    > Nonforesttype.Value = 0
    > ElevBelt.Value = 0
    > nonforestsppOS.Value = 0
    > nonforestOSCC.Value = 0
    > treecovergstype.Value = 0
    > Else
    >
    > End If
    >End Sub
    >
    >I've tried a lot of things under Else...and lots of different
    >combinations but I can't seem to get the cancel button to cancel! Any
    >help would be greatly appreciated!
    >
    >Kali


    --
    HTH - RuralGuy (RG for short) acXP WinXP Pro
    Please post back to this forum so all may benefit.

    Message posted via AccessMonster.com
    http://www.accessmonster.com/Uwe/Forums.aspx/access-forms/200706/1
     
    ruralguy via AccessMonster.com, Jun 15, 2007
    #2
    1. Advertisements

  3. Guy Guest

    Kali,

    I assume you meant:

    If Result = vbOK then
    ' Do something
    Else
    ' Do something else
    End If

    Or you can combine it in the If statement such as:

    If MsgBox("Warning: All values in section will become zero.", vbOKCancel) =
    vbOK then
    ' Do something
    Else
    ' Do something else
    End If

    Or if you have more options you can also use the Select Case as in:

    Select Case MsgBox("Do you really want to do this?", vbYesNoCancel +
    vbQuestion, "Do this Confirmation")
    Case vbYes:
    ' Yes - Do something
    Case vbNo:

    ' No -Do something
    Case Else

    ' Cancel - Do something
    End Select

    Or

    Select Case MsgBox("Do you really want to do this?", vbYesNoCancel +
    vbQuestion, "Do this Confirmation")
    Case vbYes:
    ' Yes - Do something
    Case vbNo:

    ' No -Do something
    Case Cancel

    ' Cancel - Do something
    Case Else
    (Note. this action should never be taken for the above statement, but it
    is generally good practice to include an Else for more complex scenarios)
    ' Else - Do something
    End Select

    Of course Me.Undo will also work, if returning to your last set of saved
    values is your intention.

    Hope this helps
    Guy

    <> wrote in message
    news:...
    > Hello!
    >
    > I'm fairly new to Access and VB and I've been getting along alright
    > but I've run into a problem with a message box I set up in my form.
    >
    > Situation: the field FvsNF will always be filled out. Depending on
    > the answer (yes or no) certain fields become enabled or disabled. The
    > problem is if a user decides to change their answer for FvsNF after
    > filling out the wrong fields. The incorrect fields need to go back to
    > zero if they decide to proceed with that action. However if they
    > don't want to proceed I want to give them an out without losing their
    > entries. The code I have now is:
    >
    > Private Sub FvsNF_BeforeUpdate(Cancel As Integer)
    > Result = MsgBox("Warning: All values in section will become zero.",
    > vbOKCancel)
    > If vbOK Then
    > TotalCC.Value = 0
    > OSCC.Value = 0
    > Clumpiness.Value = 0
    > ClumpDensity.Value = 0
    > ClumpSize.Value = 0
    > CrownDiff.Value = 0
    > CanopyLayers.Value = 0
    > Logging.Value = 0
    > pcc.Value = 0
    > DensOS.Value = -99
    > DensUS.Value = -99
    > sizeOS.Value = 0
    > sizeUS.Value = 0
    > sppOS.Value = 0
    > sppUS.Value = 0
    > Nonforesttype.Value = 0
    > ElevBelt.Value = 0
    > nonforestsppOS.Value = 0
    > nonforestOSCC.Value = 0
    > treecovergstype.Value = 0
    > Else
    >
    > End If
    > End Sub
    >
    > I've tried a lot of things under Else...and lots of different
    > combinations but I can't seem to get the cancel button to cancel! Any
    > help would be greatly appreciated!
    >
    > Kali
    >
     
    Guy, Jun 16, 2007
    #3
  4. Guest

    Hmmm...
    Thank you for the suggestions but I'm still having problems. I think
    I need what the "do something" code is for making it cancel because I
    can't make my code do anything but return all of the values to zero no
    matter which button I choose (OK or Cancel).

    Could I be doing something wrong with Me.undo? It doesn't seem to be
    doing anything at the moment.

    I'll keep playing around with it but if you have any other suggestions
    I'm all ears!

    Thanks again,
    Kali
     
    , Jun 18, 2007
    #4
  5. Have you single stepped the code to make sure it is executing? Me.UnDo is
    useless after you have saved the record. What values are in the table that
    the controls should return to. If the controls are *not* bound to fields in
    the underlying table/query then Me.UnDo will not work.

    wrote:
    >Hmmm...
    >Thank you for the suggestions but I'm still having problems. I think
    >I need what the "do something" code is for making it cancel because I
    >can't make my code do anything but return all of the values to zero no
    >matter which button I choose (OK or Cancel).
    >
    >Could I be doing something wrong with Me.undo? It doesn't seem to be
    >doing anything at the moment.
    >
    >I'll keep playing around with it but if you have any other suggestions
    >I'm all ears!
    >
    >Thanks again,
    >Kali


    --
    HTH - RuralGuy (RG for short) acXP WinXP Pro
    Please post back to this forum so all may benefit.

    Message posted via AccessMonster.com
    http://www.accessmonster.com/Uwe/Forums.aspx/access-forms/200706/1
     
    ruralguy via AccessMonster.com, Jun 18, 2007
    #5
  6. Guest

    Yes, I figured out that I need it to return to the values the user has
    just entered not the ones that were last saved (It was returning to
    zero which was the last saved record. It confused me at the time). I
    got it to work by using FvsNF.undo, it keeps the last values but
    unfortunately it still switches the focus and enables the wrong set of
    options for a user who canceled.
     
    , Jun 18, 2007
    #6
  7. Guest

    Alright- I'm deleting my message box and hoping the user of this form
    know's what they're doing...they'll learn quickly if they don't!
    Thanks to all for your help!
    Kali
     
    , Jun 18, 2007
    #7
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kirstie Adam

    Warning Msgbox, OK/Cancel

    Kirstie Adam, Sep 4, 2003, in forum: Microsoft Access Forms
    Replies:
    3
    Views:
    285
    Dave Elliott
    Sep 10, 2003
  2. John S. Ford, MD

    Implementing a Save, Delete or Cancel MsgBox

    John S. Ford, MD, Aug 5, 2004, in forum: Microsoft Access Forms
    Replies:
    15
    Views:
    261
  3. John S. Ford, MD

    Substituting my own MsgBox for the standard delete confirm MsgBox

    John S. Ford, MD, Aug 18, 2004, in forum: Microsoft Access Forms
    Replies:
    8
    Views:
    478
    Arvin Meyer
    Aug 20, 2004
  4. faapa via AccessMonster.com

    Own Msgbox BEFORE access's MsgBox

    faapa via AccessMonster.com, Aug 24, 2006, in forum: Microsoft Access Forms
    Replies:
    2
    Views:
    288
    Allen Browne
    Aug 24, 2006
  5. Ian

    MsgBox within a MsgBox

    Ian, Feb 14, 2009, in forum: Microsoft Access Forms
    Replies:
    3
    Views:
    175
Loading...

Share This Page