• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 495
  • Last Modified:

How to suppress the #Error in Access reports when no record set return ?

I have built some reports in MS Access.  Yet, the user find that it is not that good to display #Error in the fields when no records return for the report.  They would like to show a line of like "no records found" ... etc to override the line of #Error.  It is nearly impossible for me to built another report when detected no record through modules as there are over hundreds of reports showing #Error when no records found.  Please help urgently.  Thanks.
0
StanleyLMW
Asked:
StanleyLMW
  • 3
  • 2
  • 2
  • +3
1 Solution
 
jjafferrCommented:
Hi StanleyLMW,

I would recommend checking witha Dcount if there are Records, then Open the Report:

HowMany=Dcount("[FieldName]","TableName","[myField]=Forms![MyForm]![myField]")
if HowMany > 0 then
 Docmd.openReport ...
else
 msgbox "no records found"
endif

Hope this helps

Jaffer
0
 
shanesuebsahakarnCommented:
Just use the NoData event of the report. Put some code like this in the event:

MsgBox "No records found."
Cancel=True

This will show the message and prevent the report from opening.
0
 
peter57rCommented:
Hello StanleyLMW,

If you add this procedure to a module in your app and run it, it will create a 'NoData' event procedure for every report in your app.  The event procedure will display a msgbox as indicated in the code and then close the report.

Pete

Sub sethasnodata()
Dim x
Dim rpt As Object, mdl As Module
Dim rn As String

For Each rpt In CurrentProject.AllReports
rn = rpt.Name
'Debug.Print rn
DoCmd.openreport rn, acViewDesign, , , acHidden
Set mdl = Reports(0).Module
x = Reports(0).Module.CreateEventProc("NoData", "Report")
mdl.InsertLines x + 1, vbTab & "Msgbox  ""No data for this report - report will close"""
mdl.InsertLines x + 2, vbTab & "Cancel = True"

'Debug.Print Reports(0).OnNoData
DoCmd.Close acReport, rn, acSaveYes
Next rpt

End Sub
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
StanleyLMWAuthor Commented:
Hi Jaffer,

Thanks for your advise.  Yet, the intention of our user to print the report even with any data is for the audit concern.  As claimed by the auditors, if we don't print the report even the report don't contain any records, then no one will know there is a system error, report lost or someone intentionally hide the facts in the report.  As a result, just send a message to the user onscreen may need users to print the screen together with the blank report show behind.  I afriad that user will reject my recommendation.  Also, as for audit check, #Error seems tends to be report or system error rather than no data, therefore, #Error in case of no record will sure be query by the auditors.

Thanks.

Stanley
0
 
jjafferrCommented:
Then why don't you have a Report called ErrorReport

HowMany=Dcount("[FieldName]","TableName","[myField]=Forms![MyForm]![myField]")
if HowMany > 0 then
 Docmd.openReport "NormalReport", ...
else
 Docmd.openReport "ErrorReport", ...
endif


In the Error Report just write,
"no records found"
With the other Report identifications, like the Invoice number,
No other field that will yield #Error

jaffer
0
 
shanesuebsahakarnCommented:
In case you missed my post - try the report's NoData event. pete57r's code also uses this event and programmatically creates lines similar to the ones that I suggested in your reports for you.
0
 
will_scarlet7Commented:
To build a slightly different approach from the others, but using the same idea...

If you want the reports to print even in the event of no data, but not show the data fields, use the No Data event as proposed by Shane & Pete, but use it to hide your detail fields and show a error field.

To explain... Create an unbound textbox on your form and set the data source to something like  [="No Data. Error in data"] without the brackets, then set it's "visible" property to False (No), then in the No Data event have something like this:

Private Sub Report_NoData(Cancel As Integer)
    Me!ControlToHide.Visible = False
    Me!NoDataErrorControl.Visible = True
End Sub

That will hide the details when there is no data and display your warning message.
0
 
MootherCommented:
You can use the ISERR() function

Change the controlsource of your controls to look something like this:

=iif(iserr([CompanyName]),"NO DATA",[CompanyName])

That will let you change any cell that has an error into the data of your choice.

M
0
 
will_scarlet7Commented:
Stanley, ThanX for the points! Glad I was able to help.

Shane & Pete, You OK with that? I basically just modified your ideas.

God bless!

Sam
0
 
shanesuebsahakarnCommented:
It's fine Sam, not to worry. Some feedback from the OP would have been nice though.
0
 
StanleyLMWAuthor Commented:
Hi all,

Actually, all of your ideas are great, especially the one from Pete which I never think of.  Anyway, I should thanks for all of your prompt action.  Really appreciated ^_^

Cheers

Stanley
0
 
peter57rCommented:
Sam
No problem here.  There'll be another one along in a minute...

Pete
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now