unload event "you canceled the previous operation" error

S

Sophia

Hi Everyone;

I posted this question yesterday, but cannot find it. So, here it is again.

I have a form with a subform. If the subform is empty, I want to advise the
user. I have a message box, which asks them if they want to fill in the
subform. If they choose "yes", then the error "you canceled the previous
operation" pops up. How can I remove this error or fix what is wrong? Any
help would be appreciated.

Here is the code for the unload of the form:

Dim intResponse As Variant

If SubfrmAssessment_Details_Admission.Form.RecordsetClone.RecordCount = 0 Then
intResponse = MsgBox("Enter an Admission Assessment", vbYesNo, "Admission
assessment is not done")

If intResponse = vbYes Then
DoCmd.CancelEvent
End If
End If

End Sub

Sophia
 
J

Jeanette Cunningham

Hi Sophia
this is a common error which you can trap, so that it doesn't show.
The error is telling that the unload of the form was cancelled.

To trap that error, you need to get the error number for it. Next time you
run the form, write down the error number.

Now put some error handling code something like this:

Private Sub Form_Unload(Cancel As Integer)
On Error GoTo Err_Handler

If SubfrmAssessment_Details_Admission.Form.RecordsetClone.RecordCount = 0
Then
intResponse = MsgBox("Enter an Admission Assessment", vbYesNo, "Admission
assessment is not done")

If intResponse = vbYes Then
Cancel = true
End If
End If

Exit_Handler:
Exit Sub

Err_Handler:
If Err.Number = 2501 Then
Else
MsgBox Err.Number & " " & Err.Description
End If
End Sub

2501 is probably not the correct error number, replace it with the error
number you are getting for the error.
Now when the error occurs, it is trapped by the error handler instead of
appearing.


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
 
S

Sophia

Jeanette: Thank you for the advise, but it isn't an error which has a
number, that I can find anyway. It is a message box that pops up, after the
user chooses "Yes" to the question, prior.

Any suggestions?

Sophia
 
M

Marshall Barton

Sophia said:
Jeanette: Thank you for the advise, but it isn't an error which has a
number, that I can find anyway. It is a message box that pops up, after the
user chooses "Yes" to the question, prior.

Any suggestions?

Sophia


I think it could be a 2501 error, but it is probably coming
from the code that is trying to close the form.

How did you indicate that you wanted to close the form?
A button on the form, the X in the form title bar, or ... ?
If it was a button on the form, try trapping the error
there. If it was the title bar X, then the message is
supposed to appear so users know the window is still working
(try handling the error in the form's Error event??)
 
S

Sophia

Thank you to Marshall and Jeanette. The error resulted from using a "close"
button to close the form. If I used the "x", I didn't get the message.

The error was 3021.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top