VBA does not give you the line of code that caused the error.
It is possible to add labels to the code, and get the most recent label. For
example:
10 On Error Goto Err_Handler
20 Dim a as Integer
30 Debug.Print a / a 'Divide by zero error
40 End
You can then test ERL in your error handler to get the most recently
encountered label for the error (30 in the example above.)
However, that is a serious performance hazard. A far better routine is to
identify any line where an error is likely to occur, and break it out into a
separate procedure. There you can handle the specific problem part of the
code in a very specific way, and you don't have the nightmares about the
multiple points in the main procedure where an error is likely.
For example, if your procedure is uncertain whether there is a table named
"Table1" in the database. If you just refer to the table it will error.
Therefore you write a separate little routine to test if the table exists,
and call that instead of doing it in the main routine. Sample of the little
routine that could error:
http://allenbrowne.com/MacroInFormReport.html#TableExists
Similarly if you want to set a property of an object using DAO, many
properties don't exist if they are not set, so you get error 3270 ("Propert
not found".) It therefore makes sense to have a separate function to test if
the property exists, and create it if necessary, like this SetPropertyDAO()
function:
http://allenbrowne.com/AppPrintMgtCode.html#SetPropertyDAO