Report Error Line #

M

Mike Thomas

In Access 2000 I am tryinng to implement an error handler in an application
we have been using. Usually, when the user encounters an error, they just
call up and read the bad line to me. It gets fixed quickly.

I've written an error handling routine which writes the pertinent info to a
text file. The one thing it does not yet provide is the number of the line
the error occurred on. An alternative would be to provide the line itself.

How can this issue be solved with VBA?

Many thanks
Mike Thomas
 
A

Allen Browne

If you use line numbers (or labels) in your code, you can use ERL to get the
most recent label. If you use line numbers on every line it really slows
your code down though.

If you would prefer to avoid the issue, keep your routines short (e.g. break
them up into subroutines where appropriate).

Where you anticipate an error is likely you may want to break that bit into
a little wrapper function that handles the error for you. For example, if
you are looping through controls on a form for ControlSource (or fields in a
TableDef for Description), they will error if they don't have the property,
so you could avoid the error in your main routine with:
Public Function HasProperty(obj As Object, strPropName As String) As Boolean
'Purpose: Return true if the object has the property.
Dim varDummy As Variant
On Error Resume Next
varDummy = obj.Properties(strPropName)
HasProperty = (Err.Number = 0)
End Function

Using that kind of approach, I've only had to implement ERL once in the last
few years to pin down an error.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top