Results 1 to 6 of 6
  1. #1
    zoooza84 is offline Novice
    Windows Vista Access 2007
    Join Date
    Aug 2011
    Posts
    5

    Undo one action only

    Hello all,



    I have a form that has multiple text boxes. Was trying to add an Undo button that behaves exactly the same as the (Ctrl+Z) or the undo button used in microsoft access, word, excel ..etc. as it only undos one action in a click. When added the undo button i used just a normal button and added a code to it. if i type in different text boxes and press on the undo button it undos everything modified since the form was opened. Is there a way to change that ?

    Looking forward to read your replies ...
    Thank you in advance.

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,610
    Hi

    Can you post your code for the button?
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    zoooza84 is offline Novice
    Windows Vista Access 2007
    Join Date
    Aug 2011
    Posts
    5
    Code for the undo Button
    Private Sub Undo_Click()
    DoCmd.RunCommand acCmdUndo
    End Sub
    ----------------------------------

    Private Sub Form_Current()
    Me!Undo.Enabled = False
    End Sub
    ------------------------
    Private Sub Form_Dirty(Cancel As Integer)
    Me!Undo.Enabled = True
    End Sub

    -----------------------------

  4. #4
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,610
    Hi

    Please try this code in the OnClick event of your button.
    Code:
        Dim ctrl As Control
        For Each ctrl In Me.Form
            If ctrl.ControlType = acTextBox Then
                If ctrl.Value <> Nz(ctrl.OldValue, "") Then
                    ctrl.Value = ctrl.OldValue
                    Exit Sub
                End If
            End If
        Next
    Dose this work as you require?
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  5. #5
    zoooza84 is offline Novice
    Windows Vista Access 2007
    Join Date
    Aug 2011
    Posts
    5
    Hi,

    Thank you Bob for your Reply ...
    I tried the code, But it undos the first change i made on the form and then the one after, one after until the last change, i.e it undos the oldest.
    And it undos all changes in a certain box, i.e. if i make changes in (text box 1) and then go to (text box 2) and make more changes, if i use the button it'll undo all changes made in (Text Box 1) and if i press again it'll undo all changes made in (Text Box 2), while the action of a Ctrl+Z is undoing one action at a time.

    Is it possible to adapt that behavior (Ctrl+Z)?

    Thanks again for your help

  6. #6
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,610
    If I understand correctly, you want each click of the button to undo the the last change in whatever textbox was last changed and each subsequent click to do the same.
    I can't say that I know how to do this. Thinking out lould and without thinking it through, the only way I can think of, is to create a log table in which you could store the old value of each field. The field's "OldValue" would need to be written to the table in the AfterUpdate event of each field. The OnClicked event of the button could then be used to lookup this value and replace the current textbox value.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 7
    Last Post: 07-15-2011, 08:14 AM
  2. How do I undo the requirement to login every mdb
    By garymkrieg in forum Security
    Replies: 3
    Last Post: 07-11-2011, 03:53 PM
  3. Conditional Formatting through VBA: On Undo
    By Remster in forum Programming
    Replies: 6
    Last Post: 04-13-2011, 09:04 AM
  4. Can't run this action???
    By wwg77 in forum Programming
    Replies: 2
    Last Post: 02-02-2011, 03:22 PM
  5. Undo Table Design Changes
    By MelindaP in forum Database Design
    Replies: 6
    Last Post: 07-27-2010, 09:07 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums