• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 203
  • Last Modified:

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?
0
newbie46
Asked:
newbie46
  • 3
  • 3
1 Solution
 
peter57rCommented:
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.
0
 
Boyd (HiTechCoach) Trimmell, Microsoft Access MVPCommented:
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.
0
 
peter57rCommented:
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.
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
newbie46Author Commented:
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?
0
 
newbie46Author Commented:
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.
0
 
peter57rCommented:
It certainly looks like it doesn't do what I would expect.

However, if you use the Delete event instead you do get the ID value.

Beats me!!
0
 
newbie46Author Commented:
thank you. Using OnDelete did the trick.
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now