I have a problem I'm failing to figure out and I wonder if anyone cares to help me sort it out.
I'm trying to delete records from a subform in datasheet view. It works fine when I press the DEL key - the selected record (with a FK) is deleted after I respond affirmatively to the MSGBOX.
The problem is that I have a small redundancy built into my tables such that I actually need to delete records in two tables, and I can't get the records in both tables to be removed. The relationship between the tables does not enforce referential integrity. There is a PK/FK relationship between the tables - the table referenced by the subform holds the FK. Neither of the data sources for the subform nor the parent form reference the table with the PK. I *think* the table with the PK is essentially independent of the one with the FK. If I delete the record in the PK table, the one in the other table remains. I just can't get it to work in code and I'm hoping for a solution where the user just selects the record in the subform and hits DEL.
If I try a :
in the OnDelete event of the subform, the record in the table with the FK is deleted, but not the other (the docmd.runSQL command). I don't think it's the syntax, when I test the SQL statement in a DELETE QUERY, it works fine. Sometimes I get an error message about two users trying to edit the record at the same time. How do I prevent this? I don't know where the second user is coming in. Can I regulate the sequence of the deletes somehow? At what point in the OnDelete event is the deletion actually performed?
Can anyone help me understand why this won't work? I've been up all night trying to get this to go, so I may be simply unable to comprehend the Help files about the OnDelete event and Before/AfterDelConfirm. This is my first foray into OnDelete.
Thanks for any help anyone can give me!
I'm trying to delete records from a subform in datasheet view. It works fine when I press the DEL key - the selected record (with a FK) is deleted after I respond affirmatively to the MSGBOX.
The problem is that I have a small redundancy built into my tables such that I actually need to delete records in two tables, and I can't get the records in both tables to be removed. The relationship between the tables does not enforce referential integrity. There is a PK/FK relationship between the tables - the table referenced by the subform holds the FK. Neither of the data sources for the subform nor the parent form reference the table with the PK. I *think* the table with the PK is essentially independent of the one with the FK. If I delete the record in the PK table, the one in the other table remains. I just can't get it to work in code and I'm hoping for a solution where the user just selects the record in the subform and hits DEL.
If I try a :
Code:
response 'do you want to delete the record?'...
if response <> vbyes then
cancel=true
else
do things, including docmd.runSQL "DELETE * FROM tblWithPK WHERE ..."
end if
Can anyone help me understand why this won't work? I've been up all night trying to get this to go, so I may be simply unable to comprehend the Help files about the OnDelete event and Before/AfterDelConfirm. This is my first foray into OnDelete.
Thanks for any help anyone can give me!