Undo Button Issue

J

Jeff Byrd

We have an Undo Button on a data entry form for deleting a the entry if a
mistake is made so they can start over. After the data is entered we have a
Next Record Button programmed to allow them to enter the next record.

If the Undo button is clicked after the Next Record Button is clicked but
before they start entering a ne record it will delete the last record
entered even though it no longer shows on the form. This has caused some
records to be deleted by mistake. The user thought they were deleteing an
empty record.

Here is the code for the Undo Button:

Private Sub cmdUndoRecord_Click()
On Error GoTo Err_cmdUndoRecord_Click

DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, , acMenuVer70

Exit_cmdUndoRecord_Click:
Exit Sub

Err_cmdUndoRecord_Click:
MsgBox Err.Description
Resume Exit_cmdUndoRecord_Click

End Sub

Here is the code for the Next Record Button:

Private Sub cmdNextShowing_Click()
On Error GoTo Err_cmdNextShowing_Click


DoCmd.GoToRecord , , acNewRec
Forms!frmEagleMain!fsubMainSetShowing.Requery

Exit_cmdNextShowing_Click:
Exit Sub

Err_cmdNextShowing_Click:
MsgBox Err.Description
Resume Exit_cmdNextShowing_Click

End Sub

How can I have a Undo Button but not have it delete the last record that is
no longer showing on the form?
 
D

Dirk Goldgar

Jeff Byrd said:
We have an Undo Button on a data entry form for deleting a the entry
if a mistake is made so they can start over. After the data is
entered we have a Next Record Button programmed to allow them to
enter the next record.

If the Undo button is clicked after the Next Record Button is clicked
but before they start entering a ne record it will delete the last
record entered even though it no longer shows on the form. This has
caused some records to be deleted by mistake. The user thought they
were deleteing an empty record.

Here is the code for the Undo Button:

Private Sub cmdUndoRecord_Click()
On Error GoTo Err_cmdUndoRecord_Click

DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, , acMenuVer70

Exit_cmdUndoRecord_Click:
Exit Sub

Err_cmdUndoRecord_Click:
MsgBox Err.Description
Resume Exit_cmdUndoRecord_Click

End Sub

Here is the code for the Next Record Button:

Private Sub cmdNextShowing_Click()
On Error GoTo Err_cmdNextShowing_Click


DoCmd.GoToRecord , , acNewRec
Forms!frmEagleMain!fsubMainSetShowing.Requery

Exit_cmdNextShowing_Click:
Exit Sub

Err_cmdNextShowing_Click:
MsgBox Err.Description
Resume Exit_cmdNextShowing_Click

End Sub

How can I have a Undo Button but not have it delete the last record
that is no longer showing on the form?

If you replace the
DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, , acMenuVer70

with just

Me.Undo

I don't think you'll have that problem.

If you don't want to do that, or that doesn't work for you for some
reason, you could first test to see if you are on a new record that is
not dirty:

If Me.NewRecord _
And Not Me.Dirty _
Then
' do nothing
Else
DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, , acMenuVer70
End If

But I think Me.Undo is simpler, and it shouldn't require the test.
 
J

Jeff Byrd

Me.Undo Worked perfectly

Thank you!


Dirk Goldgar said:
If you replace the


with just

Me.Undo

I don't think you'll have that problem.

If you don't want to do that, or that doesn't work for you for some
reason, you could first test to see if you are on a new record that is
not dirty:

If Me.NewRecord _
And Not Me.Dirty _
Then
' do nothing
Else
DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, , acMenuVer70
End If

But I think Me.Undo is simpler, and it shouldn't require the test.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top