Problems with code for "On delete" event (1 Viewer)

RichO

Registered Yoozer
Local time
Today, 14:10
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
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 03:10
Joined
May 7, 2009
Messages
19,169
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.
 

RichO

Registered Yoozer
Local time
Today, 14:10
Joined
Jan 14, 2004
Messages
1,036
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)
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 03:10
Joined
May 7, 2009
Messages
19,169
Try deleting 1 ir group of recs.
View the code.
 

Attachments

  • delete.zip
    28.8 KB · Views: 62

jdraw

Super Moderator
Staff member
Local time
Today, 15:10
Joined
Jan 23, 2006
Messages
15,364
@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:

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 03:10
Joined
May 7, 2009
Messages
19,169
I think i uploaded the wring version.
 

Attachments

  • delete.zip
    34.2 KB · Views: 53

jdraw

Super Moderator
Staff member
Local time
Today, 15:10
Joined
Jan 23, 2006
Messages
15,364
@arnelgp

Yes, latest version of Delete.zip works as expected.
 

RichO

Registered Yoozer
Local time
Today, 14:10
Joined
Jan 14, 2004
Messages
1,036
That is perfect. Thank you everyone for the help!
 

Users who are viewing this thread

Top Bottom