Problems with code for "On delete" event

RichO

Registered Yoozer
Local time
Today, 00:19
Joined
Jan 14, 2004
Messages
1,036
Hi all,

When a user tries to delete a record in a particular form, I want to be able to look at what is in one of the fields in that form first. However, by the time the event fires, the record has already been pulled from the form pending confirmation from the user, and the next record is already displayed. Is there a way to catch it before that happens?

Thanks
 
You are on the right event, ondelete. each records for deletion pass through this event first, one by one. You can check the record or save it in array. The last event will be AfterDelConfirm. Here you can cancel the delete process.
 
Well, the problem is that by the time the event fires, the record I want to get information from has already been temporarily deleted.

For instance, if I am on record 5 (ID - primary key) and go to delete the record, in the code for the event, record 6 displays on the screen before the event fires and Me.My_Record_ID returns 6 instead of 5. I need to access the information in record 5 on a delete event.

I tried to store information from a particular field in a variable using the "On Current" event, but before the delete event fires, the current event appears to fire because the variable contains the information from the next record (6 as in the above example)
 
Try deleting 1 ir group of recs.
View the code.
 

Attachments

@RichO,

See this for details of the Delete events

I think you need code in the BeforeDelConfirm event, then depending on your review of the record, you continue with the Delete or Cancel the Delete.

I have seen situations, as you have, where the record ID to be deleted is moved to some area by Access and not available to you. It seems the record pointer is moved before the actual delete occurs. If you cancel the Delete action, the record ID is again made available to you.

Found this from M$oft:
After a record is deleted, it's stored in a temporary buffer. In a Microsoft Access database , the BeforeDelConfirm event occurs after the Delete event (or if you've deleted more than one record, after all the records are deleted, with a Delete event occurring for each record), but before the Delete Confirm dialog box is displayed. Canceling the BeforeDelConfirm event restores the record or records from the buffer and prevents the Delete Confirm dialog box from being displayed.

Good luck.

Note: I got an Error (type mismatch -13) with arnelgp database.
 
Last edited:
I think i uploaded the wring version.
 

Attachments

@arnelgp

Yes, latest version of Delete.zip works as expected.
 
That is perfect. Thank you everyone for the help!
 

Users who are viewing this thread

Back
Top Bottom