Originally Posted by
ajetrumpet
However, there is no way to print the offending line number. I've been all around the web looking for that, but the only solution I've seen is a 3rd party that does the job.
moreover, you could use VBA' extensibility library to loop all your code and put line numbers as comment strings at the end of the every line of code you have in your project. But I'm not sure if doing that could actually help you capture the line number that was offending anyway.
you can use extensibility in error handlers to print almost anything identifiable about errors that occur, except the line number of the error.
there's some useful info for ya!
Adam,
Here's a sample that shows line number in the error handler.
Seems ERL is undocumented, but available. I found it on the web. Try it.
Code:
'---------------------------------------------------------------------------------------
' Procedure : dListTables
' Author : Jack based
' Date : 23-11-2011
' Purpose : To list table names in database and show error handling with line number
' ***You MUST NUMBER Your Lines
'---------------------------------------------------------------------------------------
' Last Modified:
'
' Inputs: N/A
' Dependency: N/A
'--------------------------------------------------------------------------
'
Public Function dListTables()
On Error GoTo dListTables_Error
10 On Error GoTo dListTables_Error
Dim lIDX As Long
Dim lMAX As Long
20 lMAX = CurrentDb.TableDefs.Count
Dim Tdx As TableDef
30 lIDX = 0
40 For Each Tdx In CurrentDb.TableDefs
50 lIDX = lIDX + 1
60 Debug.Print Tdx.name
70 Next Tdx
80 MsgBox "complete"
90 Err.Raise 6788, , "This my own Custom error for demonstration"
100 Debug.Print "Managed to run through " & lIDX & " records before breaking it!"
110 Debug.Print "It claims there are " & lMAX & " tables..."
120 Debug.Print Err.number & ": " & Err.Description
130 On Error GoTo 0
140 Exit Function
dListTables_Error:
150 MsgBox "Error " & Err.number & " (" & Err.Description & ") in procedure dListTables of Module AWF_Related at line: " & Erl
On Error GoTo 0
Exit Function
End Function