Error Handler Always Runs (1 Viewer)

iknowkungfu

Registered User.
Local time
Today, 05:48
Joined
Jan 17, 2006
Messages
24
My code is currently running the error handler even if I comment out every single line (apart from strErrMsg and On Error GoTo) in the code, which seems to run perfectly anyway!

Code:
Function fDeleteXtabs()
'deletes xtab(n) queries 1-9

On Error GoTo fDeleteXtabs_Err
Dim strErrMsg As String

Dim intI As Integer
Dim strXtabName As String

'!-------Begin Querydef block
Dim db As DAO.Database
Dim qdfNew As DAO.QueryDef
Set db = CurrentDb()
'!-------End Querydef block

For intI = 1 To 9
strXtabName = "xtab" & intI
    If ObjectExists("Query", strXtabName) Then    'prevents it trying to delete non-existent object
        db.QueryDefs.Delete strXtabName
    End If

Next intI

fDeleteXtabs_Err:
    Select Case Err
        Case Else
            'File is open
            strErrMsg = vbNullString
            strErrMsg = "There has been a problem deleting one of the queries. "
            MsgBox strErrMsg, vbCritical, "Output Error!"
            Exit Function
    End Select

End Function

This is just an example. The other subs/functions in the same module do the same thing. This is driving me crazy!
 

namliam

The Mailman - AWF VIP
Local time
Today, 06:48
Joined
Aug 11, 2003
Messages
11,695
I will bet this is a DUH ! moment for you but...
Code:
Next intI
'<== Need an exit here  !!!
Exit function
fDeleteXtabs_Err:
    Select Case Err
        Case Else
            'File is open
            strErrMsg = vbNullString
            strErrMsg = "There has been a problem deleting one of the queries. "
            MsgBox strErrMsg, vbCritical, "Output Error!"
            Exit Function
    End Select

End Function
No exit means the error code trapping allways works....
 
Last edited:

iknowkungfu

Registered User.
Local time
Today, 05:48
Joined
Jan 17, 2006
Messages
24
Ah, the perils of being self-taught and not really understanding (from a Java p.o.v.) the haphazard error handling!

Thanks nam
 

Users who are viewing this thread

Top Bottom