Registrations are now open. Join us today!
There is still a lot of work to do on the wiki yet! More information about editing can be found here.
Already have an account?

Microsoft KB Archive/101079

From BetaArchive Wiki
Knowledge Base


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

Article ID: 101079

Article Last Modified on 5/6/2003



APPLIES TO

  • Microsoft Access 1.0 Standard Edition
  • Microsoft Access 1.1 Standard Edition
  • Microsoft Access 2.0 Standard Edition



This article was previously published under Q101079

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

SUMMARY

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:

150895 ACC95: Microsoft Access Sample Forms Available in Download Center

175066 ACC97: Microsoft Access 97 Sample Forms Available in Download Center

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: kbhowto kbusage KB101079