Solved

How can I stop error trapping from crashing Access 2007

Posted on 2011-03-08
9
420 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 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
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 

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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

726 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