Results 1 to 8 of 8
  1. #1
    azhar2006's Avatar
    azhar2006 is offline Expert
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2012
    Posts
    528

    Undo in form and subform


    Hi All
    I have a form, for example Customer, that contains an embedded subform, for example Addresses. I have a Cancel/Undo button on the main form. I understand that clicking in and out of the subform will automatically save the record. I've seen that using "DoCmd.RunCommand acCmdUndo" will undo the saved record on the main form while "Me.Undo" does nothing. I've also noticed that the subform record is not undone. What I've read is that the subform record must be deleted. However, that is not an option when the user is modifying an existing record. How can I revert the subform record .
    Thank you

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,934
    Maybe save the data to variables declared publicly in the module header (or use TempVars). And if user choses to undo, reset the field values to the variables.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    azhar2006's Avatar
    azhar2006 is offline Expert
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2012
    Posts
    528
    Thank you June
    I use this code

    If varResponse = vbNo Then
    Me.Undo
    SendKeys "{ESC}"
    SendKeys "{ESC}"
    Exit Sub
    End If

    But I want it implemented through button
    How?

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,934
    Don't understand. If you want the code behind button then create the button and put the code there.

    That code won't do any good if the record edits are already committed to the table.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    azhar2006's Avatar
    azhar2006 is offline Expert
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2012
    Posts
    528
    Yes, this is exactly what I want
    One button doing a retreat for the master and sub ​​in that one
    want the code behind button then create the button and put the code there.

  6. #6
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    There is a difference between "DoCmd.RunCommand acCmdUndo" and "Me.Undo"

    DoCmd will execute on the object that has focus and the Me shortcut will reference the object that owns the module. In other words,
    Code:
    Me.Setfocus
    ' Docmd here will reference the same object as the Me keyword
    DoCmd.Close
    
    Me.MySubform.SetFocus
    ' Docmd here will reference the SubForm object
    DoCmd.Close   'will cause an error because the Close method is unavailable to subform objects

  7. #7
    azhar2006's Avatar
    azhar2006 is offline Expert
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2012
    Posts
    528
    Thank you ItsMe
    Is it possible to clarify the code more
    Where do I put those events

  8. #8
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    The code would be most beneficial to simply read and interpret. the code does not really serve a function within an application. If you look at the code, you may understand why your Docmd works sometimes and does not work other times.

    Another point to make is, the Undo method is not always dependable because Access may commit a field/record without the user recognizing that the data has been saved. Linked subforms behave a certain way. It takes time to test your form(s) and understand their behavior.

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

Similar Threads

  1. Undo New Record IF
    By data808 in forum Programming
    Replies: 3
    Last Post: 02-22-2014, 07:59 AM
  2. Need Help: Form Undo Error
    By RichardAnderson in forum Forms
    Replies: 1
    Last Post: 10-10-2013, 12:41 PM
  3. Replies: 4
    Last Post: 07-30-2013, 02:07 PM
  4. How to undo acCmdPaste ???
    By focosi in forum Programming
    Replies: 12
    Last Post: 09-25-2011, 01:48 PM
  5. Undo one action only
    By zoooza84 in forum Access
    Replies: 5
    Last Post: 08-21-2011, 03:04 PM

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