?
Solved

How can I stop error trapping from crashing Access 2007

Posted on 2011-03-08
9
Medium Priority
?
424 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 58

Assisted Solution

by:Jim Dettman (Microsoft MVP/ EE MVE)
Jim Dettman (Microsoft MVP/ EE MVE) earned 252 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 252 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
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

 

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

771 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