I have code in the onDelete event of the subform that checks to make sure the record isn't referenced anywhere else before allowing it to be deleted. If a reference exists, then the user is prompted if they would like to mark it as inactive instead of deleting it. If they click yes, the field [Inactive] is set to True. By default, the sub-form is filtered so that inactive categories are not displayed.
What I would like to have happen is, when one or more records are made inactive (from the code in the sub-form's onDelete event) the filter should be reapplied so that record is no longer visible. The code is below:
Expand|Select|Wrap|Line Numbers
- Private Sub Form_Delete(Cancel As Integer)
- If [Reserved] Then
- MsgBox "This category is reserved by the system and can not be deleted.", vbOKOnly
- Cancel = True
- ElseIf DCount(1, "tblSalesSection", "SectionCategory = " & [CategoryID]) > 0 Then
- rVal = MsgBox("The category '" & [ShortName] & "' is in use and cannot be deleted. Would you like to make it inactive?", vbYesNo)
- If rVal = vbYes Then
- [Inactive] = True
- End If
- Me.Requery
- Cancel = True
- End If
- Cancel = True
- End Sub