ACC: How to Create an Undo Record Button on a Form

Last reviewed: October 24, 1997
Article ID: Q101079
The information in this article applies to:
  • Microsoft Access versions 1.0, 1.1, 2.0

SUMMARY

Moderate: Requires basic macro, coding, and interoperability skills.

Microsoft Access versions 1.x and 2.0 do not have a built in way to undo changes made to the current record. This article demonstrates a sample user-defined Access Basic function that you can use to undo changes made to the current record.

NOTE: In Microsoft Access for Windows 95 version 7.0, you can create a button to undo the current record by using the Command Button Wizard. For more information about the undo record command button, search for "Undoes," and then "Create Command Button That Adds, Deletes, Duplicates, Prints, Saves, And Undoes Current Record" using the Microsoft Access for Windows 95 Help Index.

NOTE: This article explains a technique demonstrated in the sample files, FrmSampl.exe (for Microsoft Access for Windows 95 version 7.0) and FrmSmp97.exe (for Microsoft Access 97). For information about how to obtain these sample files, please see the following articles in the Microsoft Knowledge Base:

   ARTICLE-ID: Q150895
   TITLE     : ACC95: Microsoft Access Sample Forms Available on MSL

   ARTICLE-ID: Q175066
   TITLE     : ACC97: Microsoft Access 97 Sample Forms Available on MSL

MORE INFORMATION

To undo the changes to the current record, you can use the DoMenuItem macro action to choose Undo Current Record from the Edit menu. However, this menu item is available only when there are changes to undo. Attempting to use the DoMenuItem action when no changes have been made to the current record causes the following error message to appear:

   Command not available: UndoCurrentRecord

This article assumes that you are familiar with Access Basic and with creating Microsoft Access applications using the programming tools provided with Microsoft Access. For more information about Access Basic, please refer to the "Introduction to Programming" manual in Access version 1.x or the "Building Applications" manual in Access version 2.0.

The following is a module using the Access Basic function UndoRecord(), which allows you to undo the current record, whether or not the record has been changed, or "dirtied":

  1. Create a module and type the following line in the Declarations section:

          Option Explicit
    

  2. Type the following procedure:

          Function UndoRecord ()
    
             On Error Resume Next
             DoCmd DoMenuItem A_FORMBAR, A_EDITMENU, A_UNDOFIELD
             DoCmd DoMenuItem A_FORMBAR, A_EDITMENU, A_UNDO
          End Function
    
    

  3. To use this function on a form, add a command button to the form and set its OnClick property to =UndoRecord().

    NOTE: In version 1.x, the OnClick property is called the OnPush property.

REFERENCES

For more information about the command DoMenuItem, search for "DoMenuItem" using the Microsoft Access Help menu.

Keywords          : FmsEvnt kbusage
Version           : 1.0 1.1 2.0
Platform          : WINDOWS
Hardware          : x86
Issue type        : kbhowto


================================================================================


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: October 24, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.