Hi Sajit,
It would be better to figure out what is causing the error and why.
Then take care of the situation so an error does not get generated. I have a
suspicion that the error is happening in the Form_Current event procedure.
Modify it to include error handling:
Private Sub Form_Current()
On Error GoTo Handle_Error
With Parent.Child36.Form
.Filter = "Desig " & IIf(IsNull([Desig]), "is null", "= '" & _
Replace([Desig], "'", "''") & "'")
.FilterOn = True
End With
Exit_Sub:
Exit Sub
Handle_Error:
MsgBox "Error " & Err.Number & ": " & Err.Description, , "Form_Current"
Resume Exit_Sub
End Sub
Test deleting a record. Do you get a message box with "Form_Current"
in the title bar, giving the error information?
If you do, it is because when you delete a record, the Form_Current
gets invoked before you get prompted to confirm the delete. This is part way
through a transaction. And what you are doing in the Form_Current may not be
allowed while a transaction is in progress. If this is indeed the case, do
this:
Add this line at the top your your subform's module below any Option
... statements, but before any subroutines/functions:
Private m_boolDeleteStarted As Boolean
Create Event Procedures for all three of On Open, On Delete and After
Del Confirm. Place the following line in Form_Open() so as to make sure it
starts out as False.
m_boolDeleteStarted = False
Place this line in Form_Delete() so as to indicate that a deletion has
started.
m_boolDeleteStarted = True
In your Form_Current add in checking to see if a record is being deleted:
If m_boolDeleteStarted Then
' Delete started, just toggle the flag to false
m_boolDeleteStarted = False
Else
' No delete started, do the normal stuff
With Parent.Child36.Form
.Filter = "Desig " & IIf(IsNull([Desig]), "is null", "= '" & _
Replace([Desig], "'", "''") & "'")
.FilterOn = True
End With
End If
Finally, in the Form_AfterDelConfirm() add these lines:
If Status = acDeleteOK Then
Form_Current
End If
This final stuff is needed because you disabled the stuff in
Form_Current, so it did not do it yet. If the user cancels the confirmation,
then a new Form_Current is automatically performed and you do not need to do
anything. But when the user accepts the confirmation, no new Form_Current is
performed, so you have to do it manually.
Hope that helps,
Clifford Bass
Sajit said:
Hello Clifford,
Ok, that is good. thats an useful one to remember.
The deletion is not by code. But manually by selecting a row selector in the
[query1 subform] form and pressing delete key. If I end the exceution of the
code when the error happens, the form continues to work. Will the solution
for this be by suppressing the error?