Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

'OpenReport action was cancelled'

Status
Not open for further replies.

PleaseGiveHelp

Programmer
Oct 29, 2002
131
US
I have created a MS Access report. When there is data to display, there is no problem. When there is NO data, I have included code (provided by someone here?) to display 'No records to display' and to prevent the report from being previewed. However, after the message box with the 'No records to display' message appears, I get another message: 'The OpenReport action was cancelled. You used a method of the DoCmd object to carry out an action in Visual Basic, but then clicked Cancel in a dialogue box. For example, you used the Close method to close a changed form, then clicked Cancel in the dialoge box that asks if you want to save the changes you made to the form.
The code behind the 'No records to display' is as such:
Private Sub Report_NoData(Cancel As Integer)

Dim strMsg As String, strTitle As String
Dim intStyle As Integer

strMsg = "This group code produces no data"
intStyle = vbOKOnly
strTitle = "No data"

MsgBox strMsg, intStyle, strTitle
Cancel = True

End Sub
How can I prevent the error message from being displayed?
 
Try placing this code in front of the DoCmd.OpenReport:
DoCmd.SetWarnings False

On the line following the DoCmd.OpenReport, add this line:
DoCmd.SetWarnings True


This should prevent the error message you described from being shown, but your special code for "no data" should still appear.

HTH,
Randy Smith
California Teachers Association
 
The help files on this event tell you that this event is designed to work when you print the report but (and I'm reding between the lines here) won't work when you try to preview it. You will have to create your own check and put it behind the event that has you OpenReport code. Something like this

Dim rst As DAO.Recordset
Set rst = CurrentDb.OpenRecordset("UnderlyingQuery")
If rst.EOF Or rst.BOF Then
MsgBox "There is no data"
Else

DoCmd.OpenReport "ReportName", acViewPreview
End If

You can use this behind the click event for a button that opens the report.

Paul
 
Let me give some additional information. My OpenReport is located elsewhere. In it, I have an On Error event. Do I need to get rid of this to use my No Data code?

Private Sub PREVIEW_REPORT1_Click()
On Error GoTo Err_PREVIEW_Report1_Click

Dim stDocName As String

stDocName = "Report1"
DoCmd.OpenReport stDocName, acPreview

Exit_PREVIEW_Report1:
Exit Sub

Err_PREVIEW_Report1_Click:
MsgBox Err.DESCRIPTION
Resume Exit_PREVIEW_Report1
End Sub
 
Private Sub PREVIEW_REPORT1_Click()
On Error GoTo Err_PREVIEW_Report1_Click

Dim stDocName As String
Dim strMsg As String, strTitle As String
Dim intStyle As Integer
Dim rst As DAO.Recordset
Set rst = CurrentDb.OpenRecordset("UnderlyingQuery")
If rst.EOF Or rst.BOF Then

strMsg = "This group code produces no data"
intStyle = vbOKOnly
strTitle = "No data"

MsgBox strMsg, intStyle, strTitle
Else

stDocName = "Report1"
DoCmd.OpenReport stDocName, acPreview

Exit_PREVIEW_Report1:
Exit Sub

Err_PREVIEW_Report1_Click:
MsgBox Err.DESCRIPTION
Resume Exit_PREVIEW_Report1
End Sub

Something like this should work. You will need to change the part that's in BOLD

Paul
 
Hi!

Find out the error number for that error and do the following:

Private Sub PREVIEW_REPORT1_Click()
On Error GoTo Err_PREVIEW_Report1_Click

Dim stDocName As String

stDocName = "Report1"
DoCmd.OpenReport stDocName, acPreview

Exit_PREVIEW_Report1:
Exit Sub

Err_PREVIEW_Report1_Click:
If Err.Number = TheErrorNumberYouFound Then
Resume Next
Else
MsgBox Err.DESCRIPTION
Resume Exit_PREVIEW_Report1
End If

End Sub

hth
Jeff Bridgham
bridgham@purdue.edu
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top