Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

unload event "you canceled the previous operation" error 1

Status
Not open for further replies.

Dophia

Technical User
Jul 26, 2004
263
CA
Hi Everyone:

I have a form with a subform. If the user tries to close the form, without filling in the subform, I want a message to advise them of the empty subform. The problem is that when the user chooses to stay on the form, in answer to a message box, the following error pops up..."you canceled the previous operation". Can anyone help me to address this error and not have it pop up? The code on the unload event is:

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
 
Duane: I looked at the website, but I am at a loss as to what I am supposed to use there. Can you be more specific?

Thanks for you help,
Sophia
 
Duane: I installed the program, but it only gives me an "unload error", which I guess is not my problem. My problem is that the message "you canceled the previous operation" is displayed.

Is there any way to get rid of that message?

Help,
Sophia
 
I did post it in my initial question.

Sophia
 
I'm not sure that I know what you mean. The only thing that I left out was the following, which is the first line.

Private Sub Form_Unload(Cancel As Integer)
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
 
What happens if you replace this:
DoCmd.CancelEvent
with this ?
Cancel = True

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks for the suggestion. Now I get the message "no current record".

Any other ideas?
Sophia
 
I am using the unload event since the user can go to another record and then not be aware of the empty subform.

Sophia
 
I just found the problem. I am using the "close" button on the form. If I use the "x" to close, there is no message. How can I use the "close" button and not get that message? Any suggestions?

Private Sub CloseForm_Click()
On Error GoTo Err_CloseForm_Click

DoCmd.SetWarnings False
DoCmd.Close

Exit_CloseForm_Click:
Exit Sub

Err_CloseForm_Click:
MsgBox Err.Description
Resume Exit_CloseForm_Click

End Sub


 
That's where you would enter the error handling to ignore the specific error number:
Code:
Private Sub CloseForm_Click()
On Error GoTo Err_CloseForm_Click

DoCmd.SetWarnings False
    DoCmd.Close

Exit_CloseForm_Click:
    Exit Sub

Err_CloseForm_Click:

Select Case Err.Number
    Case 2501
        'ignore
    Case Else
        MsgBox Err.Description
End Select
Resume Exit_CloseForm_Click
    
End Sub

Duane
Hook'D on Access
MS Access MVP
 
Thank you Duane! That works.

(The error number was 3021)
Sophia

 
The command Docmd.close is not good form, IMO. You should specifically state what you want the code to close, as docmd.close will close whatever object has the focus. To explicity state the object use the command form:

Docmd.close acForm, Me.Name

Look at docmd.close in the Help file for a full explanation.

 
Vbajock: I'll try that. Thanks for the tip.

Sophia
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top