For all of my procedures I have just before the end a label generally name
Exit_ProcedureName
and a few more commands including
Exit Sub.
After that I have a label
Err_ProcedureName
followed by some error handling ending with
Resume Exit_ProcedureName
In some procedures I use recordsets and querydefs so after the Exit_ProcedureName label I set about closing any that have been used. If there is an error then the recordsets and querydefs still get closed.
The problem is, what happens if an error occurs before a querydef or recordset has been set. I will then get an error in the Exit_ProcedureName part of the code.
I tried to get round this by checking that the recordsets and querydefs were not nothing before I closed them, using IsNothing as recommended in Access Help. But IsNothing doesn't exist and I can't use = nothing since this generates an error.
Sooooo, any ideas how I can avoid errors in my error handling?
Cheers,
Pete
PS - Example code below
**Start of code**
..whole load of code using a querydef qdf..
Exit_ProcedureName:
Set db = nothing
qdf.close
Set qdf = nothing
Exit Sub
Err_ProcedureName:
MsgBox "Error: " & Err.Number & " - " & Err.Description & "blah blah"
Resume Exit_ProcedureName
End Sub
**end code**
Exit_ProcedureName
and a few more commands including
Exit Sub.
After that I have a label
Err_ProcedureName
followed by some error handling ending with
Resume Exit_ProcedureName
In some procedures I use recordsets and querydefs so after the Exit_ProcedureName label I set about closing any that have been used. If there is an error then the recordsets and querydefs still get closed.
The problem is, what happens if an error occurs before a querydef or recordset has been set. I will then get an error in the Exit_ProcedureName part of the code.
I tried to get round this by checking that the recordsets and querydefs were not nothing before I closed them, using IsNothing as recommended in Access Help. But IsNothing doesn't exist and I can't use = nothing since this generates an error.
Sooooo, any ideas how I can avoid errors in my error handling?
Cheers,
Pete
PS - Example code below
**Start of code**
..whole load of code using a querydef qdf..
Exit_ProcedureName:
Set db = nothing
qdf.close
Set qdf = nothing
Exit Sub
Err_ProcedureName:
MsgBox "Error: " & Err.Number & " - " & Err.Description & "blah blah"
Resume Exit_ProcedureName
End Sub
**end code**