My app has more than 100 forms that have sub forms. In most of them there is not a main query and sub query, the sub form just returns a list on the form to view. There are the 5 main documents that consist of a main query linked to a sub query. They have parent records and child records.
1. The preference is to almost never delete records, just mark them as inactive and store information on who deleted the record.
2. But the app must still have the ability to delete a record.
3. The forms that do not have a sub query is no problem and the VBA in blue delete a record as expected.
Private Sub btn16DeleteOne_Click()
If MsgBox(Prompt:="Are you sure to delete this record?", Buttons:=vbYesNo, Title:="From PERFAC") = vbYes Then
'On Error Resume Next
DoCmd.RunCommand acCmdDeleteRecord
If Err.Number = 0 Then
MsgBox Prompt:="Deleted", Buttons:=vbOKOnly, Title:="From Perfac"
Else
MsgBox Prompt:="There is no record to delete!", Buttons:=vbOKOnly, Title:="From PERFAC"
End If
Else
MsgBox Prompt:="Not Deleted", Buttons:=vbOKOnly, Title:="From PERFAC"
End If
End Sub
4. The app has 5 forms that are the main documents, and they have main queries linked to sub queries, and the referential integrity is set, see image.
5. The code in blue does not result in deleting a record on these 5 forms. The same delete button and VBA that works well on so many forms, does something on these 5 forms I find very strange. I googled and searched but no success yet.
6. I would like to learn how to set up a module that delete a record on these 5 forms that have a linked sub form. Then call the delete action from these 5 documents.
7. Or if it is better, just learn what VBA will delete a parent record and child record, on the local form. Of course, if I learn the technique on one form, I will know how to do it on all of them, since there are a few more.