Question : Error Handler won't close forms

Hi Experts,
I use an Error Handling routine to trap all errors, log them to a text file and then either continue if possible, or close any open forms and get the user to log back into the system via a form opened in the error routine - see the code extract from the Error Handler below.

My problem is that the loop through the form closing routine does not in fact close all open forms - that is why I'm checking "Forms.Count > 0" again after the close loop has finished.

Is it possible to force a close on all open forms or is it that the form in which the error occurred cannot be closed? If that's the case, is there another way around this other than quitting the app?
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
If Forms.Count > 0 Then
               For intCounter = 0 To Forms.Count - 1                  
                       'MsgBox "Close Forms(intCounter).Name=" & Forms(intCounter).Name
                       DoCmd.Close acForm, Forms(intCounter).Name
               Next intCounter
           End If

           If Reports.Count > 0 Then
               For intCounter = 0 To Reports.Count - 1
                   DoCmd.Close acReport, Reports(intCounter).Name
               Next intCounter
           End If
              
 
           DoCmd.SetWarnings True
           If Forms.Count > 0 Then  'CHECK IF ALL FORMS HAVE BEEN CLOSED
               MsgBox "Error Handler could not recover - you will have to re-open the d/base"
               On Error Resume Next
               DoCmd.Quit
           Else               
               DoCmd.OpenForm "frm_error_recovery"  'open the error recovery form to log back in again
           End If

Answer : Error Handler won't close forms



By the time you have run into your "unexpected error", the damage has been done, and no amount of clean shutdown is going to resolve it. We get this question from time to time, and the answer is always the same - you really cannot stop, avert, or otherwise diminish corruption by trying to stop Access from closing. By that time, it's too late.

I'd urge you to concentrate your efforts on discovering WHY your database is corrupting. The most common causes seem to be poor network connections - does this occur for ALL users, or just one or two? If for all, then it's a common network resource, like a bad cable or router/switch. If it's only for one or two users, then most likely it's an issue with their hardware.

Are you using any sort of remoting technologies? That is, are all your users running the database in a local WIRED network? Or do you have users who run the database across a VPN, or via a wireless connection? Either of those can cause very frequent corruption.
Random Solutions  
 
programming4us programming4us