5
votes

I have encountered a problem in Access 2010 for Windows:

  1. Launch a report using doCmd.OpenReport
  2. Set "Cancel = True" in an event associated with the report
  3. Close Access
  4. Access continues to run as a "phantom" process and must be killed in Task Manager. Access cannot open another database until this process is killed. The task initially shows some CPU utilization but quiets down to 0%.

I discovered this while using doCmd.OpenReport to launch a report. The report opens a form in the Report_Open event. The form prompts the user for report parameters and allows them to press "OK" to display the report or press "Cancel". The On Click event for "Cancel" sets "Cancel = True".

It appears that OpenReport() is not responding gracefully to the cancel. This seems like a frequently used technique so I hesitate to call it a bug and am wondering if I am doing something wrong. Actually... the more I explain this, it does sound like a bug. At this point, I am hoping somebody has a workaround or that I am missing something obvious.

This is just a simplified example I created to illustrate the problem:

form

Private Sub Form_Open(Cancel As Integer)
On Error GoTo errHandler

DoCmd.OpenReport "Test Report", acViewPreview, , , acDialog

Exit Sub

errHandler:
Select Case Err.Number
Case 2501   ' Cancelled by user, or by NoData event.
    MsgBox "Report cancelled, or no matching data.", vbInformation, "Information"
Case Else
    MsgBox "Error " & Err & ": " & Error$, vbInformation, "Form_Open()"
End Select
Resume Next

End Sub

report

Private Sub Report_Open(Cancel As Integer)
    Cancel = True
End Sub
2
I cannot reproduce your error. Have you tried the above code in a fresh database consisting only of a form and report? Have you compacted & repaired and decompiled recently? - Fionnuala
Thanks for looking at it. I created a new DB on a different computer running Office 2010 and Win7 (vs Win8). I copy and pasted the code I posted on this page. Exact same problem. MSACCESS.EXE remains running in Task Manager at 0% CPU utilization. No other Access DB's can be opened until I kill the task. I also verified that SP1 was installed on both computers. - user1882222
I beg your pardon! I just realized that there was a further step to reproducing the error, and that is to close the database after running the code. Yes, I am getting this error. - Fionnuala

2 Answers

5
votes

The reason for the problem in this case is acDialog:

 DoCmd.OpenReport "Test Report", acViewPreview, , , acDialog

I think you will find:

 DoCmd.OpenReport "Test Report", acViewPreview

Works without problems.

Edit re Comment

You should not need to cancel the report. For the most part, it is better to avoid errors than to trap them, so check for data and get parameters before opening the form. Move the form from the report open event to step of its own and use DLookUp or a query to check for data before launching the form.

0
votes

I'm not in a position to test this problem, so I'll just offer a generic solution: Remove the data/recordset/recordsource from the report definition.

You can apply the recordsource to the report after you have determined the parameters. If the report is canceled, it is canceled without ever having a data connection.