Results 1 to 9 of 9
  1. #1
    5 Star Lounger
    Join Date
    Mar 2001
    Posts
    989
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Cancelling BeforeUpdate (2002)

    I'm using the Before Update event of a text to check the content. I can set Cancel = True to prevent the updating, but how can I reverse the entered text? txtThis.Undo doesn't seem to work? Thanks, Andy.

  2. #2
    5 Star Lounger
    Join Date
    Apr 2003
    Location
    Hampshire, United Kingdom
    Posts
    602
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Cancelling BeforeUpdate (2002)

    txtThis.OldValue should return the previously stored value, so use:

    txtThis=txtThis.OldValue
    Waggers
    If at first you do succeed, you've probably missed something.

  3. #3
    5 Star Lounger
    Join Date
    Mar 2001
    Posts
    989
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Cancelling BeforeUpdate (2002)

    I get an error message saying the BeforeUpdate event is preventing Access from saving the data in this field..

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Cancelling BeforeUpdate (2002)

    In what sense does txtThis.Undo not work?

  5. #5
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Cancelling BeforeUpdate (2002)

    No, you can't change a value in BeforeUpdate or you will get errors. Cancel = True cancels the update. Depending on what you want to happen and whether this is a bound or unbound control, you may need to allow the update (not set Cancel=True) but set a module level variable like mblnCancel = True and then check for that in the AfterUpdate and reset the value of the cell to its OldValue.
    Charlotte

  6. #6
    5 Star Lounger
    Join Date
    Apr 2003
    Location
    Hampshire, United Kingdom
    Posts
    602
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Cancelling BeforeUpdate (2002)

    Yep, sorry, I got it slightly wrong! The code you had was correct (txtThis.Undo) according to the Help on BeforeUpdate. However, there is a KnowledgeBase article that highlights the problem we're encountering:

    ACC: Commands Not Available During BeforeUpdate Event

    Interestingly the article only refers to 97 and earlier version, but it's clearly still a problem in XP and 2003.
    Waggers
    If at first you do succeed, you've probably missed something.

  7. #7
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts

    Re: Cancelling BeforeUpdate (2002)

    I'm using Access2000, and I can use this code with no errors:
    Cancel = True
    txtThisControl.undo
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

  8. #8
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Cancelling BeforeUpdate (2002)

    Undo works fine for a bound control, but it doesn't do anything for an unbound control. That is not very surprising, since there is no stored value for an unbound control. Perhaps Andy is using an unbound text box.

  9. #9
    5 Star Lounger
    Join Date
    Apr 2003
    Location
    Hampshire, United Kingdom
    Posts
    602
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Cancelling BeforeUpdate (2002)

    Yep, I was using an unbound textbox for testing. I tried using the code below as an alternative, but this did produce the error message (for fairly obvious reasons when I think about it <img src=/S/doh.gif border=0 alt=doh width=15 height=15>):
    <div style="width: 100%; background-color: #FFFFFF;">Cancel = True
    txtThis = txtThis.OldValue</div hiblock>or <div style="width: 100%; background-color: #FFFFFF;">Cancel = True
    txtThis.text = txtThis.OldValue</div hiblock>
    I was getting into thinking that the above should be equivalent of txtThis.Undo, and so the KB article was relevant, but in fact was heading down a dead end
    <img src=/S/hiding.gif border=0 alt=hiding width=70 height=24>
    Waggers
    If at first you do succeed, you&#39;ve probably missed something.

Posting Permissions

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