• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 428
  • Last Modified:

How can I stop error trapping from crashing Access 2007

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
Tom Lobb
Asked:
Tom Lobb
4 Solutions
 
Jim Dettman (Microsoft MVP/ EE MVE)PresidentCommented:
<<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
 
Andrew_WebsterCommented:
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
 
Tom LobbAuthor Commented:
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Tom LobbAuthor Commented:
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
 
Jim Dettman (Microsoft MVP/ EE MVE)PresidentCommented:
 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
 
Jeffrey CoachmanCommented:
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
 
Tom LobbAuthor Commented:
I'll try these when I get back to my office. Thanks
0
 
AccessYourBiz_ComCommented:
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
 
Tom LobbAuthor Commented:
I think that the database may be corrupt. The same code works elsewhere and I tried all the things suggested.
0

Featured Post

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Tackle projects and never again get stuck behind a technical roadblock.
Join Now