In MS Access (2003), I have a SELECT query consisting of both left and inner joins, displayed in datasheet view as subform. I would like to give users the ability to delete multiple records while in datasheet view. The default delete that occurs when the user chooses "Delete Record" from the context menu of a record does not work; the record disappears from the datasheet view but continues to exist in the underlaying tables and re-appears on refresh of the view.
I attempted to define delete queries in the Form_delete event, using the CodeContextObject object to get the primary key value of the selected record, and then running DELETE FROM tablename WHERE id=keyValue. This works but Access displays a warning "The Microsoft Jet database engine disabled the process because you and another user are attempting to change the data at the same time." The record is then actually deleted from the table, but instead of disappearing from the view, it is displayed as #Deleted. How do I override the default delete procedure in datasheet view?
Here is the SELECT query:
SELECT *
FROM [SELECT *
FROM ((GeneralTable as G
INNER JOIN SpecificTable as S ON G.id = S.id)
LEFT JOIN Assigned as A on G.id = A.id)]. AS Q1
LEFT JOIN People AS P ON Q1.pID = P.pID
WHERE (((Q1.isPrimary) Is Null Or (Q1.isPrimary)=True));
I have changed the names of the tables, but the design is SpecificTable inherits from GeneralTable, with People being assigned to records in SpecificTable in a many-to-many relationship. This query selects all records in SpecificTable, and the person, if any, assigned as primary to the record. When a record is deleted, the record in the People table should not be deleted, but the records in G, S, and A should be deleted.
DELETE
statement asDELETE FROM YourTableToDelete WHERE EXISTS (<table expression>);
– onedaywhen