Solved

Recording Degugging Information

Posted on 2011-02-15
24
529 Views
Last Modified: 2012-08-13
I have a function that records the errors in the program to a table.  Is there any way of finding either the line number or line of code that won't execute so I can record that as well?  
0
Comment
Question by:trbaze
  • 12
  • 8
  • 3
  • +1
24 Comments
 
LVL 77

Expert Comment

by:peter57r
ID: 34898491
Provided you have applied line numbers then ERL will give you the error line number.
0
 
LVL 3

Author Comment

by:trbaze
ID: 34898571
How about just the line of code then, like docmd.Openform?
0
 
LVL 75
ID: 34898593
Among the many other things the free cool app does, it will add line numbers.  I use it daily.

http://www.mztools.com/v3/mztools3.aspx

mx
0
 
LVL 3

Author Comment

by:trbaze
ID: 34898695
How do you reference the line number?
0
 
LVL 75

Accepted Solution

by:
DatabaseMX (Joe Anderson - Access MVP) earned 250 total points
ID: 34898750
As Peter noted ... using the ERL function.

Example:

Public Function APP_AutoExec() As Boolean

          Const sFx As String = "APP_AutoExec"
10        DoCmd.Hourglass True
20        DoCmd.Echo False
30        On Error GoTo APP_AutoExec_Error
         
40        Application.CommandBars.DisableAskAQuestionDropdown = True
50        Application.MenuBar = "zMbMDMM"
60        If SysCmd(acSysCmdAccessVer) >= 11 Then Application.SetOption "Themed Form Controls", True
         

APP_AutoExec_Exit:
70        Err.Clear
80        DoCmd.Hourglass False
90        DoCmd.Echo True
100       Exit Function
         
APP_AutoExec_Error:
110       MsgBox "An unexpected error has occured" & vbCrLf & vbCrLf & _
                 "Error Information --------------------" & vbCrLf & _
                 "Error Number: " & Err.Number & vbCrLf & _
                 "Description: " & Err.Description & vbCrLf & vbCrLf & _
                 "Code Fx: " & sFx & vbCrLf & vbCrLf & _
                "Line Number: " & Erl & vbCrLf & vbCrLf & _
                 "Steps to take:" & vbCrLf & vbCrLf & _
                 "1) Take a screen shot of this error message and email it to the Database Administrator, with a brief explanation of what led up to the error." & vbCrLf & vbCrLf & _
                 "2) Close then reopen the database, then retry the operation. If the error continues, notify the database administrator immediately." _
                 , 48, "App AutoExec Error"
120       GoTo APP_AutoExec_Exit


End Function
   
0
 
LVL 3

Author Closing Comment

by:trbaze
ID: 34898846
That works perfect!  Thank you very much!
0
 
LVL 3

Author Comment

by:trbaze
ID: 34900082
This just corrupted my DB.  The errors I get are that the expression entered does not match the procedure name.  Includes everything like OnLoad, OnCurrent, OnCllick.
0
 
LVL 75
ID: 34900104
What just corrupted your DB ?

mx
0
 
LVL 3

Author Comment

by:trbaze
ID: 34900114
The code  and line numbers added by the toolbar.
0
 
LVL 75
ID: 34900150
I've been using MZTools for years and have never seen an instance of failure, especially adding Line Numbers.

Where did you add Line Numbers ?

mx
0
 
LVL 21
ID: 34900183
Pardon me for jumping in ...

trbaze, have you installed all the Office 2007 update so that you have SP2?

Also make use that you manually compile the VBA code after pasting any code or running add-in like MZtools.
0
 
LVL 3

Author Comment

by:trbaze
ID: 34900331
Yes I have the sp2 update, also the code complied fine.  I ran the program, then it started giving me the event errors.  The forms, reports and modules are all giving same errors.
0
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
LVL 3

Author Comment

by:trbaze
ID: 34900350
Now its saying VB project cannot be read.
0
 
LVL 75
ID: 34900369
Now, you didn't try to use the *example* code I posted did you?  That was just to show an example of how ERL can be used.

Can you upload your db ?

mx
0
 
LVL 3

Author Comment

by:trbaze
ID: 34900477
I didn't use your code.
Inventory.accdb
0
 
LVL 75
ID: 34900732
Do you have a backup?

I hate to say this, but the VBA project IS corrupted and I cannot open - without Access deleting all code modules.

mx
0
 
LVL 3

Author Comment

by:trbaze
ID: 34900746
Thats the problem I had.  I have a backup thats a day old, so some changes won't be there.  Why would that happen?
0
 
LVL 3

Author Comment

by:trbaze
ID: 34900768
I'm not sure if it was the add-in or not.  It was working fine until I added a Cancel as integer to an OnEnter event on a button.
0
 
LVL 75
ID: 34900972
"Why would that happen?"
I am 99.9987531% sure that MZTools did not do this.  I have MZTools on 4 of my systems, as well as two systems at work (A2003 and A2010) ... never ever a problem.

"it was working fine until I added a Cancel as integer to an OnEnter event on a button."

You can't do that.  The On Enter event does not contain any arguments.  Nor can any arguments be added to any built in Form or Control event.

However, you should have just gotten a Compile error immediately.  I can't possibly image how that would have resulted in this corruption.

I would send it to Wayne (http://www.everythingaccess.com/accessdatabaserepair.htm), explain what you did ... and see if he can fix it ...

mx
0
 
LVL 21
ID: 34901319
Whenever I have seen the VBA code get corrupted like this the database was not recoverable at all.

In the past there was an issue with the VBA editor that would corrupt the VBA code for the enter database.

This is also another good reason to split the databases. I regular work on updates in a copy of the front end. I will  import the changes into the master front end by using exporting/import objects to a text file similar to how Safe Source works.

Hopefully you are making regular backups as you go. Especially before running an toll that makes mass changes.



0
 
LVL 3

Author Comment

by:trbaze
ID: 34901448
If i were to distribute this as an MDE file that will run under access runtime, will it be able to run the erl code?
0
 
LVL 75
ID: 34901481
"will it be able to run the erl code?"
Definitely ... in fact, you REALLY want it in an MDE ... for possible troubleshooting later on.

mx

0
 
LVL 21
ID: 34901698
I totlaly agree with mx.

The last step I use just before creating my MDE/ACCDE is to add line numbers and do some code clean up.

Here is how I do it: http://www.fmsinc.com/free/newtips/vba/errorhandling/linenumber.html
0
 
LVL 3

Author Comment

by:trbaze
ID: 34901713
Thanks again for your help, I really appreciate it.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now