Re: Repost: DoCmd.RunCommand acCmdDeleteRecord does nothing.

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



You cannot delete the record before it is saved. The approaches you are
using attempt to save the record before it is deleted, and the messages
associated with the failed save differ (or don't exist.)

If you don't want the record, it makes sense to undo any edits in progress.
You can then delete the record if it exists:
If Me.Dirty Then
Me.Undo
End If
If Not Me.NewRecord Then
DoCmd.RunCommand acCmdDeleteRecord
End If

That gives no error if the record can't be saved because it is invalid, and
also avoids the error message if there is no record to delete. (Presumably
there is no point telling the user that the record cannot be saved, since
they want to be rid of it anyway.)

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"vainglory" <paolo@xxxxxxxxxxxxxx> wrote in message
news:1153205796.488374.284650@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Hi,

Sorry for the repost, but I didn't get any comments regarding this:

I was revising my code as recommended to avoid using:

DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70

and use:

DoCmd.RunCommand acCmdDeleteRecord

But as soon as I did, I noticed that my delete button seemed to die.
That is, whenever I violate referential integrity, or attempt to delete

a record that has nulls in a required field or primary key or has
duplicates in a primary key I get no error whatsoever! In fact,
nothing happens! Is this normal? I don't even get warning message
even though warnings is turned on.

Then, I replaced:

DoCmd.RunCommand acCmdDeleteRecord

with

DoCmd.RunCommand acCmdSelectRecord
DoCmd.RunCommand acCmdDeleteRecord

and I got my error messages back. But strangely, I still have no
warning
messages. Please I am dying of curiosity as to why this is happening.
Any ideas?

Thanks in advance,

Paolo


.


Quantcast