Close Main Form Upon Error in Subform

gray

Registered User.
Local time
Today, 12:15
Joined
Mar 19, 2007
Messages
578
Hi

Here's one I've been meaning to tackle properly for a while. It's a Form/Subform situation where there are events in the subform.

Where an error occurs in the subform (a checkbox click event or whatever) I want to close the form and especially want to run the main form unload sub.

When in the Main form it's easy enough, I have a

DoCmd.Close acForm, Me.Name, acSaveNo

in my error handling.

But waht's the best way of closing both main form and subform when an error occurs in the subform?

I tried just calling
DoCmd.Close acForm, Me.Name, acSaveNo
in the error handler of the subform but this does not close the main.

I tried

DoCmd.Close acForm, Me.parent.form.Name, acSaveNo

but it refuses to run that, I get the End/DeBug prompt

I also tried making my main form close and unload events public and calling them from the error handler of the subform... again Access does not permit this... I get the End/DeBug prompt

Any more ideas anyone... ? thanks
 
Why not simply

DoCmd.Close acForm, "MainFormName", acSaveNo

FYI, acSaveNo doesn't prevent the Record from being saved, it prevents any Form Design Changes from being saved.

Linq ;0)>
 
Hi

Thanks for the reply. I've tried various permutations of the doCmd.close in the subform but they result in an

error 2585 "This action canot be carried out while processing a form or report event".

So some process is still running... you'd think there would be a way to force-close a form?
 
Perhaps if you can tell us, in plain English, exactly what you're trying to accomplish here we can make some cogent suggestions.

Closing a Form/Subform when an error is popped sort of negates the entire point of having error-handlers.

Linq ;0)>
 
Sure... thanks

I use SQL transactions (begintrans/commit/rollback etc) with ADODB Rs's in my forms. I set up a new connection in the form-open and set it to CurrentProject.Connection. The forms in question are modal.

The problem I am utlimately trying to fix is that (especially during development) when a form fails the connection does not get closed properly, it 'ties up' Access and I have to use Windows task manager to kill Access.

I added a close of the connection to the unload event of the main form and this nicely closes the connection unless there is a failure in the subform... in which case it does not necesarily close/unload the main form... back to square one.

It occured to me that it would be possible to close the main-form from the subform error handlers so that the main-form unload event always get fired no matter what... little did I think it would be this tricky... :)

Hope that makes sense? thanks
 

Users who are viewing this thread

Back
Top Bottom