Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2004-09-29
12
Medium Priority
?
453 Views
Last Modified: 2012-05-05
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
Comment
Question by:StanleyLMW
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +3
12 Comments
 
LVL 27

Expert Comment

by:jjafferr
ID: 12177627
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
 
LVL 41

Expert Comment

by:shanesuebsahakarn
ID: 12177654
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
 
LVL 77

Expert Comment

by:peter57r
ID: 12177731
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
Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

 

Author Comment

by:StanleyLMW
ID: 12177737
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
 
LVL 27

Expert Comment

by:jjafferr
ID: 12177765
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
 
LVL 41

Expert Comment

by:shanesuebsahakarn
ID: 12177780
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
 
LVL 15

Accepted Solution

by:
will_scarlet7 earned 1000 total points
ID: 12177833
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
 
LVL 3

Expert Comment

by:Moother
ID: 12177970
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
 
LVL 15

Expert Comment

by:will_scarlet7
ID: 12178057
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
 
LVL 41

Expert Comment

by:shanesuebsahakarn
ID: 12178066
It's fine Sam, not to worry. Some feedback from the OP would have been nice though.
0
 

Author Comment

by:StanleyLMW
ID: 12178098
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
 
LVL 77

Expert Comment

by:peter57r
ID: 12178280
Sam
No problem here.  There'll be another one along in a minute...

Pete
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question