Mike & Doris Manning
mikedorism at adelphia.net
Thu Feb 5 15:40:57 CST 2004
It can't find frmPermitEntry because the form has closed and all references to the form's controls have been destroyed. I would set a boolean variable to true if the cancel status is met. Then just before asking them if they want to exit, I would look at the value of the boolean. If it is true, go ahead and exit...otherwise ask if they want to exit. Doris Manning Database Administrator Hargrove Inc. www.hargroveinc.com -----Original Message----- From: accessd-bounces at databaseadvisors.com [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Hollis,Virginia Sent: Thursday, February 05, 2004 12:32 PM To: 'Access Developers discussion and problem solving' Subject: [AccessD] Error Closing Form I have the code shown below on a command button that closes a form. The form is a data entry form with a checkbox that will cancel the request by changing the status to 3 (canceled). If the status = canceled then the form will close. If an entry has been made on the form, there are certain required fields that must be completed before closing. Problem: Everything works fine except when I check the Cancel box. The status changes from 1 (Pending) to 3 (Canceled) & the form will close, but I get an error, "Can't find frmPermitEntry refered to in a macro of visual basic code". I tried commenting out different sections of the code, but I can't find the problem. What I don't understand, I have used this same code before without any problems. What am I missing? ******************** If PStatusID = 3 Then DoCmd.Close 'Request has been canceled If Forms!frmPermitEntry.Dirty = True Then 'Data Entered? Yes If Len(PRequestorID & "") = 0 Then MsgBox "A requestor must be entered." & vbCrLf, vbCritical, " Entry Required" PRequestorID.SetFocus ElseIf Len(PNeedByDate & "") = 0 Then MsgBox "The date needed must be entered." & vbCrLf, vbCritical, " Entry Required" PNeedByDate.SetFocus ElseIf Len(PTypeWork & "") = 0 Then MsgBox "The type of work must be entered." & vbCrLf, vbCritical, " Entry Required" PTypeWork.SetFocus Else Response = MsgBox("Do you want to Exit?", vbYesNo + vbQuestion, "Exit") If Response = vbNo Then PRequestorID.SetFocus Else DoCmd.RunCommand acCmdSaveRecord DoCmd.Close acForm, "frmPermitEntry" End If End If Else DoCmd.Close acForm, "frmPermitEntry" End If _______________________________________________ AccessD mailing list AccessD at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/accessd Website: http://www.databaseadvisors.com