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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Print Preview button producing error message

Status
Not open for further replies.

serino64

Programmer
Feb 25, 2003
32
US
Hello Everyone,

I have run into a problem and I cant quite figure a way around It.

I have created a form which has a listbox which contains a list of reports. The listbox refers to a table for the report names.
I then have a Print Preview button which then looks to see if the Listbox is visible and if "Yes" it then previews the report. On the On Click event of the preview button I have the follwowing:

[Blue]Private Sub Preview_Click()
DoCmd.RunMacro "minimize"
If [lstreport1].Visible = True Then
DoCmd.OpenReport lstreport1.Column(0), acPreview
[lstreport1].Visible = False
ElseIf Me.[lstreport2].Visible = True Then
DoCmd.OpenReport lstreport2.Column(0), acPreview
[lstreport2].Visible = False
Else
End If
End Sub[/Blue]

If the report contains data it will open and everything is fine, but if there is no data then then I run into an error. The Reports properties are setup as follows.

The OnOpen event contains an event procedure which basically hides the database: [blue]DoCmd.RunMacro "mcrRestore" [/blue]

On the "On No Data" Event procedure there is:
[blue]MsgBox "There is no data for for the Builder Report during this period"
Cancel = True [/blue]

The error occurs when I click the preview button-I then receive the message "There is no data for for the Builder Report during this period". (Which is fine) I then receive the VB error "The OpenReport was cancelled" and when I look at the debug window it refers to:

[Blue]Private Sub Preview_Click()
DoCmd.RunMacro "minimize"
If [lstreport1].Visible = True Then
[red]DoCmd.OpenReport lstreport1.Column(0), acPreview
[lstreport1].Visible = False[/red]
ElseIf Me.[lstreport2].Visible = True Then
DoCmd.OpenReport lstreport2.Column(0), acPreview
[lstreport2].Visible = False
Else
End If
End Sub


How can I resolve this issue?
 
Use an error handler to trap the report cancelled message.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top