user1882222
user1882222

Reputation: 65

MS Access - "phantom" process created by canceling report

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

Upvotes: 5

Views: 675

Answers (2)

david
david

Reputation: 2638

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.

Upvotes: 0

Fionnuala
Fionnuala

Reputation: 91326

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.

Upvotes: 5

Related Questions