Link to home
Start Free TrialLog in
Avatar of newbie46
newbie46

asked on

How does Access 2007 know ID of record being deleted from form?

I am inserting records into a Change History table when a record is deleted from a form (using the Delete button on the keyboard). Yet, when deleting the record, Access doesn't seem to know what record is being deleted.

How do I access information about the record being deleted? I have the following code in VB:
Private Sub Form_BeforeDelConfirm (Cancel As Integer, Response As Integer)
Dim db As DAO.Database

Set db = CurrentDb()

db.Execute "INSERT INTO ChangeHistory (RecordID, DateDeleted) VALUES ( '" & _
me.RecordID & "', Now())"


How can I access the RecordId of the record being deleted?
Avatar of peter57r
peter57r
Flag of United Kingdom of Great Britain and Northern Ireland image

The delete button the keyboard will delete values in a field , not a record.

You need to add your own Delete record button, or use the Delete on the ribbon.
If you click on the record selector (or some other method of selecting the record) first then pres the delete key it will definitely delete the record.
i agree - i didn't read the question as saying that.

If that's what the poster is doing then I don't see why the id would not be available.
Avatar of newbie46
newbie46

ASKER

TheHiTechCoach,
When I click on the record selector and then click delete on the keyboard, the record is deleted. Before the record is deleted, I need to track its record id and store this in a Change History table. How do I access the record's id prior to it being deleted?
When I step through BeforeDelConfirm code in VBA, the record id is null. Is there a way to access this id. I tried using me.recordset.absoluteposition and me.recordset.recordcount to try to access this id, but to no avail.
ASKER CERTIFIED SOLUTION
Avatar of peter57r
peter57r
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thank you. Using OnDelete did the trick.