Access 2003 - Reports - Display message when no record exists
Hi,
I have a query in access which fetches Records based on a parameter supplied by the user at runtime. parameter "Enter Date:"
Now I created a Report to display the above results.
There could be occasions where there could be no records avaiable.
During those occasion a message needs to be displayed "No Records available for this date."
I was thinking of putting an invisible Label, in the pageHeader section, to do this job, which becomes visible only when there is no record fetched in the detail section. Some coding in this regard would be of much help.
Thanks in advance :wave::afrog:
Re: Access 2003 - Reports - Display message when no record exists
Was my post so complicated :eek:
Re: Access 2003 - Reports - Display message when no record exists
The below code pops up a message box when no records are fetched...
Code:
Private Sub Report_NoData(Cancel As Integer)
MsgBox "No records match the criteria you entered.", vbExclamation, "No Records Found"
Cancel = True
End Sub
Now how about my original query of displaying a message in the report itself in the page header or some other location when no records are available..
Re: Access 2003 - Reports - Display message when no record exists
One solution could be to call a new rpt inside that procedure (Report_NoData) and this new rpt only has the desired message of "No records match the criteria you entered" fixed in the report header section or where you like to
JG
Re: Access 2003 - Reports - Display message when no record exists
Thanks jggtz
But I believe there is a way to access individual elements/controls of a report I've seen something like that in CR (even that I've forgotten!!!) :eek:
If we can get control of that then as suggested by you we can display a message in the header of the same report. Also note when there is no record the txt boxes in the details section display #Error may be this may come in handy :sick:
I faintly remember how it was done in CR.
You get the obj of the report, then access its individual sections->controls
something like
Code:
report.GroupHeader(0).Text(0).Text="my message"
Re: Access 2003 - Reports - Display message when no record exists
Here is how you can change a reports text object.
Code:
Dim objT As CrystalDecisions.CrystalReports.Engine.TextObject
objT = DirectCast(rpt.Section2.ReportObjects("txtReportType"), CrystalDecisions.CrystalReports.Engine.TextObject)
objT.Text = "Amounts For " & strCYear
If strRptType = "ALM" Then
objT = DirectCast(rpt.Section2.ReportObjects("txtHeader"), CrystalDecisions.CrystalReports.Engine.TextObject)
objT.Text = "Average Lift Minus(31-31/Used) Report"
End If
Me.CrystalReportViewer1.ReportSource = rpt
also you will need this,
Code:
Imports CrystalDecisions.CrystalReports.Engine