Undoing/canceling record addition

  • Thread starter Thread starter Brian Langley
  • Start date Start date
B

Brian Langley

Morning folks-

Can anyone direct me to some code that will undo record addition? I have a
popup that needs a command button to cancel- delete the record and close the
form.

I was thinking a macro would do it through OnClick: RunCommand:
DeleteRecord, but since the form is Data Entry/Add Only it won't let me
delete it. Is there code that will do this? Or can the macro reassign the
DataEntry property to false and then back to true (I think I can do this
based on options in the expression builder, but am not sure the syntax)?

Cheers
Brian
 
The first part of this example undoes any edits that are in progress.

The second part deletes the record, ifyou wanted that as well:

Private Sub cmdUndo_Click()
If Me.Dirty Then
Me.Undo
End If

If Not Me.NewRecord Then
runcommand acCmdDeleteRecord
End If
End Sub
 
Can you please tell me how to cancel a delete? When the prompt box displays
the message, "You are about to delete 1 record(s). If you click YES you
won't be able to undo this Delete operation. Are you sure you want to delete
these records?
YES or NO.

If you select YES, then it deletes correctly. However, if you select NO, I
get a run-time error '2501': The RunCommand action was canceled.
END or DEBUG or HELP.

How do I avoid this error message if the user selects NO? I've tried if
cancel=true then.... but it does not work.

Thank you!

geri

I have the following code:
RunCommand acCmdDeleteRecord
 
gg said:
Can you please tell me how to cancel a delete? When the prompt box
displays the message, "You are about to delete 1 record(s). If you
click YES you won't be able to undo this Delete operation. Are you
sure you want to delete these records?
YES or NO.

If you select YES, then it deletes correctly. However, if you select
NO, I get a run-time error '2501': The RunCommand action was
canceled.
END or DEBUG or HELP.

How do I avoid this error message if the user selects NO? I've tried
if cancel=true then.... but it does not work.

Thank you!

geri

I have the following code:
RunCommand acCmdDeleteRecord

RunCommand is a method of the DoCmd object and anything you do with DoCmd that
is cancelled will raise error 2501. You need an error handler that is set up to
ignore that error.

On Error GoTo ErrHandler

DoCmd.RunCommand acCmdDeleteRecord

Egress:
Exit Sub

ErrHandler:
Select Case Err.Number
Case 2501
'ignore
Case Else
(your error handling code)
End Select
Resume Egress
End Sub
 

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

Back
Top