Kill a Modal Form

gray

Registered User.
Local time
Today, 22:34
Joined
Mar 19, 2007
Messages
578
Hi

Access 2007, .mdb

I have an unlinked mainform/subform used as Modal. I have close button allowed on the mainform.

If the VB fails in my subform my error trapping includes a :-

DoCmd.Close acForm, Me.Parent.Form.Name, acSaveNo

It does not close however. None of my custom exit/cancel buttons or whatever will work and neither does the form's close button (X).

The only way I can get out of this is to kill Access from the Windows TaskList. Seems a bit drastic... anyone know of any orher way to kill the offending form?

thnx
 
Why don't you solve the error instead?

Are you sure it ever gets to that line of code? Have you tested it with a Msgbox?
 
Hi

I'm developing the form and so it fails with different things each time..... it's just a pain having to kill and re-start Access every go and especially as Access has the habit of throwing one's (even saved) work away .... I thought there might be some obscure CNTRL key or PF key that might kill the form... ?
 
Like I asked, how are you sure it's getting to that line of code?
 
Hi

Ran it thru' the debug... it gets to the line but doesn't close the parent form... if I leave it as

DoCmd.Close acForm, me.Form.Name, acSaveNo

It closes neither the main or subform..... The form close (X) button is active so one can close the form manually but I need to close the sub and main form from the sub so as not to confuse the user.... hmm.. a timer in the mainform maybe?
 
Yes... a timer does the trick... for anyone else reading ...

Declare a Boolean in the main form e.g.

Public Timer_Close_Main_Form As Boolean

Make the mainform timer public:-

Public Sub Form_Timer()

then check the boolean in the timer:-

Me.TimerInterval = 0
If Timer_Close_Main_Form = True Then
DoCmd.Close acForm, Me.Form.Name, acSaveNo
End If

In the subform error-trap:-

Me.Parent.Timer_Close_Main_Form = True
Me.Parent.TimerInterval = 100
 
I know you've managed to solve it using the timer but I believe it can be accomplished without it.

* Can I see your error trapping procedure?
* What if you put the actual form name in there instead of using Me.Name?
* Any chance of uploading a test db?
 
Hi

Thanks... appreciate the assistance. It's taken me a while to butcher my test .mdb to get it workng long enough to perform the test..... so....

1. Open Addrs_Dtls_Form
2. Click on any record's name
3. Click the Sort button
4. Click the Cancel button on the Sort Fields form - (to confirm this works OK)
5. Re-open the Sort form as at 2 and 3
6. Click on any of the 'Selected' checkboxes in the Sort form's subform. This produces a deliberate error.
7. The End or DeBug prompt appears
8. Take either option but ultimately choose End
9. The form does not close and all the buttons have become inoperative... incl the (X) button
10. Close Access from Windows task manager

This error occurs in the current event so I guess the result is to be expected but there have been others outside of the current.

I wondered if there was a CNTRL key to kill the active form but, if there is, Msoft have kept it a close secret! :)

thanks
 

Attachments

Just had a look and I see what you mean. I guess the Current event is not the sort of place where you place that kind of code because the event is still running and needs to gracefully complete.

Have you thought about ways to stop that error from happening? Check if that field exists in the list of field names in the recordset and proceed if it does.
9. The form does not close and all the buttons have become inoperative... incl the (X) button
10. Close Access from Windows task manager
I noticed this behaviour too and I don't have time to trace the problem. All I can say is when the error occurs you need to hit the 'Stop' button after you Debug or End. Once you hit Stop you don't need to go to Task Manager. Now on a normal form if you hit End it should stop all running code and reset itself but it's not the case with your form. So there must be something going on somewhere, perhaps the form is corrupt or you have a timer or something else.

By the way, when you hit Debug you still have to Stop the running code. So in your step 8 since you didn't mention hitting the Stop button my guess is you didn't know about this.
 
Aha... The Stop Button? No I don't know about that... I've looked around the Debug menu but can't see such a thing... or did you mean the End button of the end/debug prompt?

cheers
 
It looks like a Stop button like you have on cd players. It's actually a Reset button.
 
Found it.... handy tip that!.... thanks
 

Users who are viewing this thread

Back
Top Bottom