Solved

How can I stop error trapping from crashing Access 2007

Posted on 2011-03-08
9
414 Views
Last Modified: 2012-05-11
I use the No Data event to output a message to the user that there is no data for the report. At the end of the sub, I set Cancel to true to cancel the event. This causes Acces to crash. If I don't use the event, the report previews and Access doesn't crash.
0
Comment
Question by:Tom Lobb
9 Comments
 
LVL 57

Assisted Solution

by:Jim Dettman (Microsoft MVP/ EE MVE)
Jim Dettman (Microsoft MVP/ EE MVE) earned 63 total points
ID: 35071253
<<This causes Acces to crash. If I don't use the event, the report previews and Access doesn't crash. >>

  not sure what you mean by crash, but if your opening this report in code, you need to trap error 2501 in the calling code.  

  Setting Cancel = True in the NoData Event simply causes the report opening to be canceled.

  When control returns to the calling code, it's sees a cancel to its OpenReport request.

JimD.
0
 
LVL 8

Assisted Solution

by:Andrew_Webster
Andrew_Webster earned 63 total points
ID: 35071424
MZ Tools make a free toolbar for Access that includes a gadget that will add error handling painlessly for you.  I've used it for ages.  Grab it as http://www.mztools.com/v3/download.aspx
0
 

Author Comment

by:Tom Lobb
ID: 35071692
By crash, I mean that I get the message that Access has encountered a problem and needs to close. I have the option of repairing the database and I can send a message or not to Microsoft. If I repair the database and close the window, the database starts up again.

I use this function to open the report. I call it from the property sheet with =RptPrev("Name")
Public Function RptPrev(RptName As String)
' preview the specified report
On Error Resume Next
    DoCmd.OpenReport RptName, acViewPreview
End Function
0
 

Author Comment

by:Tom Lobb
ID: 35071717
By crash, I mean that I get the message that Access has encountered a problem and needs to close. I have the option of repairing the database and I can send a message or not to Microsoft. If I repair the database and close the window, the database starts up again.

I use this function to open the report. I call it from the property sheet with =RptPrev("Name")
Public Function RptPrev(RptName As String)
' preview the specified report
On Error Resume Next
    DoCmd.OpenReport RptName, acViewPreview
End Function
0
Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

 
LVL 57
ID: 35071864
 Nothing wrong with that per say, but I would change it just a bit:

Public Function RptPrev(RptName As String) as Boolean

   ' Preview the specified report
    On Error Resume Next
    DoCmd.OpenReport RptName, acViewPreview
 
    RptPrev = True

End Function

  Just to be specific about what is getting passed back and to actually pass something back.  However it should still work as it was (you'd be passing back a empty variant).  A2007 did tighten up on a lot of things, so this may be the issue.

  If that doesn't clear it up, I would create a new DB, import everything into that and test again as you may have some corruption.

JimD.
0
 
LVL 74

Assisted Solution

by:Jeffrey Coachman
Jeffrey Coachman earned 62 total points
ID: 35072539
Like Jim, I don't see anything really wrong with your code.

Can you test this in Access 2003?
Does it work if you comment out the Error handler?
What if you made this a procedure?
What if you hardcode the Report name...
Does this happen on all machines?
Does this happen if a similar code is used in another DB?
...etc
0
 

Author Comment

by:Tom Lobb
ID: 35072986
I'll try these when I get back to my office. Thanks
0
 
LVL 3

Accepted Solution

by:
AccessYourBiz_Com earned 62 total points
ID: 35074456
Sounds like you have some corruption or you are running SP3 on Windows XP.

First thing I would do is decompile you MDB, compact it, then recompile it. Of course make sure youhave a backup before doing this but I have never had a problem with decompile.

To decompile:
1)Create a new shortcut to MSACCESS.EXE with a /decompile parameter after it.
2)Run the Shortcut
3)Open your mdb file. I would hold down the shift key to prevent any auto loading of forms or macros if you have that sort of thing.
4)Close the database
5)Open up access with a normal shortcut
6)compact your database
7)open database and compile
8) test to see if the problem is gone.

If that doesn't work you can try performing an office Repair via the control panel.

For more info on the decompile check out:
http://www.fmsinc.com/microsoftaccess/performance/decompile.asp

Good luck!
0
 

Author Closing Comment

by:Tom Lobb
ID: 35108793
I think that the database may be corrupt. The same code works elsewhere and I tried all the things suggested.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

708 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

13 Experts available now in Live!

Get 1:1 Help Now