I have a form (frmEditCategor ies) containing a sub-form (subCategories) that allows the user to add, delete, and change information that categorizes inventory items. The main form is not bound, and there is no parent/child relationship between the main form and the subform. I did this because every other form the users deal with have a form/subform set-up, and they are comfortable editing, deleting, and navigating within that setup.
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:
The Me.Requery line is throwing an error: "Error 3246: Operation not supported in transactions." I think I understand what it means about transactions, being in the middle of a delete operation at the time. But I can't think of how to get around it. Any advice would be appreciated.
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:
Code:
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
Comment