Prevent opening a report if no data to show
We can prevent a report open if no data to show, and for this we use two forms depending on the version of Access:
1 - All versions of ACCESS
Place the code below in the properties of the report, the event 'Enabling'
Use the event Enabling (Activate) Report:
Private Sub Report_Activate ()
If DCount ("*", Me.RecordSource) = 0 Then
MsgBox "No records to display" vbDefaultButton1, "Error!"
AcReport DoCmd.Close, "report name"
End If
End Sub
2 - From version 7 (Access 95) was added the event 'if no data', then we can urilizar the following code:
Private Sub Report_NoData (Cancel As Integer)
MsgBox "No data in the report.", VbInformation, "Error!"
Cancel = True
End Sub
To see running download the example: Prevent opening report






























I wonder which version of Access that you use for opening the system Sales on my machine, a message format database is not recognized.
All examples are made in Access 2003. Can I send in another format prior to Access 2003 if you want.
Good morning, I'm doing a table form, this form there are three fields in each column with formulas (expressaão) examples:
Calculado1 Period - (minus) period calculado2
(Space w / put date) (space p / put date)
Calculado3 Period - (minus) period calculado4
(Space w / put date) (space p / put date)
Calculado5 Period - (minus) period calculado6
(Space w / put date) (space p / put date)
after he makes the result of the difference of date then it multiplies by 30 with relation to a monthly "X", then the result of expression in these columns will result in adding another one with a field called Credit, and p / appears result in the field Crediton gotta fill all the columns as fields are not of datasn or to put the date 00/00/0000 if I got up it was already enough, just missing this w / end my work.
If you can help me thank you and congratulations for the blog Abrç. Thiago
If you have not understood Poso send w / you by e-mail from already thank you for your attention.
You can use the NZ function
Calculado1 Period - (minus) nz (calculado2 period)
Hello Jose
I downloaded your sales system, MS has many
to DEBUG, downloaded to system sales for me.
grateful.
You have a sample file of how to use the DLookup function = e = DLookup
Hi, I came to know his blog, and wish good evening
bjsss
I await your visit
It is super simple to prevent an open report
1) Open the report in DESIGN and open the form properties.
2) Go to the Event tab and select IF NO DATA
3) Click the ellipsis (...)
4) Enter the code below
Private Sub Report_NoData (Cancel As Integer)
MsgBox ("NO INFORMATION FOR THIS REPORT")
End
End Sub
5) Close the editor VISUAL BASIC
6) Note that appears in option EVENT PROCEDURE IS NO DATA
7) You can run your program.
There are many ways to reach a goal, just choose and be creative.
You can use the NZ function
Calculado1 Period - (minus) nz (calculado2 period)
Good morning! You can create a button on the form to perform a backup of the database?
Grateful.
Congratulations on the job! I visit your site daily ... BTW, I would indicate the site http://www.iAulas.com.br there you will find more than 10,000 textbooks for free download all kinds of subjects, including handouts Access ... I have helped ...
was really looking wonderful examples of access
Thank you very much