MS Access: Capture values when record is deleted from subform
Asked Answered
M

1

6

When I delete data in a Form or SubForm, I want to catch the deleted record in the BeforeDelConfirm event. I know it is possible to get the data out of the "delete buffer" to use it for something else.

I do not want to use the Delete event. I know it is possible to get the data from there before it is actually deleted in the Recordset, but I want it on the BeforeDelConfirm event out of the "delete" buffer.

I know it is possible because I made it a few years ago, but I do not find the right code and did not found it in several Google sessions.

Merrow answered 16/4, 2014 at 22:58 Comment(5)
I am 99% sure that you HAVE to use the On Delete event, otherwise there would be no reason to use it, you would go straight to BeforeDelConfirm. Voting up to be proven wrong :)Turbine
What is your purpose? Why do you want to avoid OnDelete()? Do you want to prevent the deletion for a particular situation? (If so, instructions are easy to find.)Lowercase
@Turbine Why should someone then use the BeforeDelConfirm Event if you can not access the deleted data.Merrow
@Lowercase I do not want to avoid it. At the moment I use it for my purpose, but I know it is possible and want me to remember how it works to get the data this way.Merrow
@user3543239 I meant that if it was possible to get the deleted data on the BeforeDelConfirm event, there would be no use for the OnDelete event. At this point the BeforeDelConfirm event exists in order to bypass the default confirmation box and supply a custom one, or forcefully cancel the deletion under some case.Turbine
L
5

Allen Browne points out that the Delete event fires for each record, but BeforeDelConfirm fires once -- even if multiple records are selected for deletion. So there is no opportunity to capture those values.

The value of the deleted record(s) is not available in BeforeDelConfirm. Use the Delete event to get the value.

It is possible to delete several records at once, e.g. if you select multiple records in a continuous form or datasheet. The Delete event fires once for each record, and the value is available each time. Then the BeforeDelConfirm and AfterDelConfirm events fire once for all deletes, but the values are not available at that time. You therefore need to write the value(s) of the deleted record(s) to an array or temp table in the Delete event if you want to read them in the BeforeDelConfirm event.

He provides an example: http://members.iinet.net.au/~allenbrowne/AppAudit.html

Lowercase answered 3/6, 2015 at 20:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.