Solved

How can I stop error trapping from crashing Access 2007

Posted on 2011-03-08
9
419 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
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 

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
 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

856 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