Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error handling reporting the wrong line number

Status
Not open for further replies.

hondaman2003

Programmer
Mar 3, 2008
202
US
I have access 2002 but am working with a database that is access 2000. I have detailed error handling built into every procedure. The errors are saved on a table for review later. The incorrect line number is being reported. For example it tells me line number 9490, but that line number does not exsist. I have literally typed a line number for every line in the VBA code. Can you help?
 
How are ya hondaman2003 . . .

Don't you think some sample code is in order! [surprise]

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Absolutely not...... =)

Option Compare Database
Option Explicit
Const HandleErrors As Boolean = True

Private Sub NameOfSub()
11001 If HandleErrors Then On Error GoTo ErrorHandler

<commands>

ErrorHandler:
ErrorLogging

End Sub

Sub ErrorLogging()
Select Case Err.Number
Case 2293, 2501
MsgBox ("Email not sent")
Case Else
Dim rsErrorLog As Object
Set rsErrorLog = CurrentDb.OpenRecordset("Error log")
rsErrorLog.AddNew
rsErrorLog![Error number] = Err.Number
rsErrorLog![Error description] = Err.Description
rsErrorLog![Error date and time] = Now()
rsErrorLog![Error line] = Erl()
rsErrorLog![Computer number] = Environ("computername")
rsErrorLog![LAN ID] = Environ("USERNAME")
rsErrorLog.Update
rsErrorLog.Close
MsgBox ("Error reported devolopment team")
End Select

End Sub
 
hondaman2003 . . .

Not quite getting this yet, but [blue]Erl()[/blue] is directly involved. Have a look at the function or post it here for a look see.

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Where you see the following is an example of all subroutines in the form. There are commands that have line numbers in front of them. If an error occurs it goes to the ErrorLogging subroutine. The error logging subroutine above basically saves the error information in a table.

Private Sub NameOfSub()
11001 If HandleErrors Then On Error GoTo ErrorHandler

<commands>

ErrorHandler:
ErrorLogging

End Sub


Does that clarify?
 
hondaman2003 . . .

I meant to post the [blue]Erl()[/blue] function!

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Erl() isn't a function that I defined. To my knowledge it's the same as Now()
 
hondaman2003 . . .

Confusing as Now() is the current date & time stamp! Surely this is not what you intend to assign to [blue]rsErrorLog![Error line][/blue]?

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
I'm sorry, what I meant was that the Erl() function is the same as Now() in that it's an access function. Erl() to my knowledge is supposed to be the line number of the variable. I can get this to work but in many cases it returns a line number that doesn't exsist.
 
hondaman2003 . . .

I found no reference or documentation for [blue]Erl()[/blue] is access 97, 2000, 2003 or XP. However I did find info thru google. Apparently documentation wa no longer provided after VB3.

Since you've shown Erl() is not working properly, might I suggest the [blue]CVErr[/blue] function! Check it out in VBA help.

I hope it helps . . .


Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Do you actually put a line number in front of every line? I think Erl will only work if the line has an actual number in front of it. That's more a guess though, I'm aware of Erl's existance, but never actually used it.

Joe Schwarz
Custom Software Developer
 
TheAceMan1, I cannot see where the CVErr command will provide me a line number.

JoeAtWork, Yes, I have actually numbered every line in the code. The Erl command is giving me a number, but it's giving a number that doesn't exsist.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top