Prevent opening a report if no data to show

Posted on Wednesday, May 20, 2009 - 22:01 | by admin |

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

RSS feed | Trackback URI

13 Comments »

Comment by Michelle
2009-06-02 21:00:48

I wonder which version of Access that you use for opening the system Sales on my machine, a message format database is not recognized.

Comment by Administrator
2009-06-03 11:01:56

All examples are made in Access 2003. Can I send in another format prior to Access 2003 if you want.

Comment by Thiago Santos
2009-07-31 14:24:46

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.

Comment by Administrator
2009-07-31 20:38:53

You can use the NZ function

Calculado1 Period - (minus) nz (calculado2 period)

Comment by Luis
2009-08-09 19:59:58

Hello Jose

I downloaded your sales system, MS has many
to DEBUG, downloaded to system sales for me.
grateful.

Comment by Alan
2009-08-12 17:29:22

You have a sample file of how to use the DLookup function = e = DLookup

Comment by Dri Viaro
2009-08-13 17:44:57

Hi, I came to know his blog, and wish good evening
bjsss

I await your visit :)

Comment by Washington
2010-02-27 21:58:53

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.

Comment by Administrator
2010-04-25 18:05:39

There are many ways to reach a goal, just choose and be creative.

Comment by Bruce
2010-05-19 19:13:56

You can use the NZ function

Calculado1 Period - (minus) nz (calculado2 period)

Comment by Otavio Barros
2011-01-27 10:26:41

Good morning! You can create a button on the form to perform a backup of the database?
Grateful.

Comment by Andrew
2011-07-26 22:43:07

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 ...

Comment by jose oliveira
2011-08-30 18:47:59

was really looking wonderful examples of access
Thank you very much

Name (required)
Email (required - not published)
Website
Your comment ( Decrease | Increase )
You can use <a href="" title=""> <abbr title=""> <acronym title=""> <blockquote cite=""> <b> <cite> <code> <del datetime=""> <em> <i> <Q cite=""> <strike> <strong> in the comments.

Presentation

Avatar

Thank you for visiting.
Subscribe to feed not to miss any messages.

Here in blog I will provide examples of working with Microsoft Access and also ask questions to those who ask. More

Want to subscribe?

Subscribe or subscribe by email:
Enter your email:


Ads