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

No Data Event - Print Message on Report

Status
Not open for further replies.

tubbers

Technical User
Jun 23, 2004
198
US
I'm running Access Project (2000) as a front-end for SQL Server 2000. I have a report based on a stored procedure, which works perfectly.

Right now, when there is no data a message box pops up and says there's no data and the report will be closed. The user then clicks OK and goes on their way.

What I would like to happen is for the report to print and display the "no data" message on the actual printed report.

This is the code on the report, which is functional:
Code:
Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)
Const White = 16777215
Const GRAY = 14211288
       
            If (Me![LineNum] Mod 2) = 0 Then
                Me![Shading].BackColor = White
            Else
                Me![Shading].BackColor = GRAY
            End If

End Sub


Private Sub Report_NoData(Cancel As Integer)
   
    Cancel = True
    MsgBox "No data found! Closing report."


End Sub

I've tried putting a label in the report's header as well as the detail section that would be visible only if there is no data but it errors out on the Detail_Print event (Error 2427 - You entered an expression that has no value).

Code:
Private Sub Report_NoData(Cancel As Integer)
   
    Me!lblNoData.Visible = True

End Sub

I've not been able to find any information on the web or within the forum. Any help or direction would be appreciated.
 
How about:
Code:
If Me.HasData Then
    If (Me![LineNum] Mod 2) = 0 Then
        Me![Shading].BackColor = White
    Else
        Me![Shading].BackColor = GRAY
    End If
Else
    Me!lblNoData.Visible = True
End If
 
That worked great and so simple. I wasn't aware of HasData previously and it was just what I needed.

Thanks for your time!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top