Forum Discussion
Willem1310
Oct 08, 2024Copper Contributor
Delete a record in a table from a report
Who can help me,
I made a rapport from a table, I want to make a button in the rapport which deletes the record in the table.
I did try to use a macro RecordDelete and assign it to a button, but when I click it access stays that it is in read only mode, but it is not.
who has a solution
All the best Willem
3 Replies
Sort By
- Ken_SheridanCopper Contributor
It can be done in a report opened in Report View. Add a button to the report's Detail section, with code like this in its Click event procedure:
Dim strSQL As String
strSQL = "DELETE * FROM Contacts WHERE ContactID = " & Me.ContactID
CurrentDb.Execute strSQL, dbFailOnError
Me.Requery
where ContactID is the primary key of a Contacts table to which the report is bound.
But why would you want to do this in a report rather than a form? The latter gives you much more control over the process. For examples of what can be done in a bound form take a look at DeleteDemo.zip in my public databases folder at:
https://1drv.ms/f/c/44cc60d7fea42912/EhIppP7XYMwggESpAAAAAAABaDKZCllSuweYBPJ5zKa3cg
- George_HepworthSilver Contributor
On the possibility that by "rapport" you mean a form that displays a summary of data, and not "report", you should also consider whether the recordsource of that object is a table, or a query with multiple tables joined for the purpose of that summary.
If that is the case, the problem could be that the query is not updateable because of the way it is written. - George_HepworthSilver Contributor
Forms are designed for adding/updating/deleting records.
Reports are designed for displaying data.
If you need to delete a record, the appropriate tool, therefore, is a form, not a report.