[AccessD] Return to same record after cancel.

Penn White ecritt1 at alltel.net
Tue Apr 4 05:45:16 CDT 2006


Just discovered a lovely little one-two punch that everyone probably already 
knows about but was new to me.

If the user cancels an operation, I wanted to take them back to the record 
they were working on before they opened some other window.  The example is 
when my user clicks on the "Add New Record" command button.  If he/she 
changes his/her mind and decides to cancel the add operation, then I want to 
return to the record they were working on before they opened the "Add New 
Record" popup.

Because of some other things that are done in that popup, I need to requery 
the original form during the Cancel.  As you know, when the form is 
requeried, it returns to the first record in the form.

The workaround I discovered is this:

Private Sub cmdCancel()
   Dim lngCurrRec as Long
    lngCurrRec = Forms!PreviousFormName.CuirrentRecord

    -------
    Whatever other code you want in the Cancel event
    including the Forms!PreviousFormName.Requery
    -------
  DoCmd.GoToRecord acDataForm, "PreviousFormName", acGoTo, lngCurrRec

  DoCmd.Close acForm, Me.name

Exit Sub

This won't work if you've added any new records, of course, but it works 
great for a Cancel operation.  I've used recordset bookmarks a lot for 
similar operations but they won't work in this instance and this is so clean 
and neat, I really like it.

Penn




More information about the AccessD mailing list