473,394 Members | 1,717 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Don't Want Report to Open if Message Box Appears Saying No Data for Report

I'm trying to stop a report from opening after a message box tells user that no data is available and return to the previous form
Dec 8 '17 #1

✓ answered by PhilOfWalton

Try
Expand|Select|Wrap|Line Numbers
  1. Private Sub Report_NoData (Cancel As Integer)
  2.   MsgBox "There are no records", vbExclamation, "No Records"
  3.   Cancel = True
  4. End Sub
  5.  
Phil

4 2085
PhilOfWalton
1,430 Expert 1GB
Try
Expand|Select|Wrap|Line Numbers
  1. Private Sub Report_NoData (Cancel As Integer)
  2.   MsgBox "There are no records", vbExclamation, "No Records"
  3.   Cancel = True
  4. End Sub
  5.  
Phil
Dec 8 '17 #2
NeoPa
32,556 Expert Mod 16PB
It's worth pointing out that the code that calls the report to open will error when this is used.

It's the right way to do it but just bear in mind you also need to handle the error in the calling code unless you want it to crash.
Dec 8 '17 #3
yes this worked but as NeoPa said now I have a error on clicking ok
Dec 13 '17 #4
PhilOfWalton
1,430 Expert 1GB
So you need to trap the Error.

Try something like this on the button that opens the report
Expand|Select|Wrap|Line Numbers
  1. Sub MyButton_Click
  2.  
  3.     On Error Goto Report_Open_Err
  4.  
  5.     DoCmd.OpenReport MyReport, acPreview
  6.  
  7. Report_Open_Exit:
  8.     Exit Sub
  9.  
  10.  Report_Open_Err:
  11.     If Err = 2501 Or Err = 3420 Then          ' Open Report Cancelled or form opened
  12.         Exit Sub
  13.     Else
  14.         Msgbox Err & "   " & Err.Description
  15.     End If
  16.  
  17. End Sub
  18.  
Phil
Dec 13 '17 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Andrew Parsons | last post by:
Apologies if this is an old chestnut, but I can't find an answer anywhere! I have a form which has a button which opens a report. This all works perfectly well. However, I am trying to set up a...
7
by: simonmarkjones | last post by:
Hi, I have a report i would like created based upon a date the user types in. I have a query which in the criteria section of my date field i have put . The report is created fine when a...
1
by: jj | last post by:
I created a dynamic report and the fields is displayed base on the query. The report contains about 34 fields so if the query has 34 fields, all 34 fields in the report shows up. But if the query...
6
by: icony | last post by:
Hi everyone, Here's my problem. I have a report that i want to use with the command openreport. The report open and close in a fraction of a second. I cant see why i cant view the thing. Cause i...
1
by: Amita K | last post by:
Hello Friend I am preparing a crystal report with Master-Detail kind of data. i have placed a subreport such that it shall display detail data after each row of main report. I know we can place...
4
by: Andrew Meador - ASCPA, MCSE, MCP+I, Network+, A+ | last post by:
I have created a report. This report needs to display records between two dates entered by the user. I put two text boxes on the report so I can enter the start and end date - I set them to use an...
3
by: kmnotes04 | last post by:
Could anyone tell me how to restrict the date range for items that appear on a report? Old items from previous years appear on the report. I was asked to have only this year's items (and beyond)...
0
by: sarvmardan | last post by:
how to open a report in access containing filtered data using two combo boxes on form and a button to click. let i have two fields and other is . two comboboxes are combo11 and combo9. plz post...
1
by: Leah Beard | last post by:
I have a table with a stored hyperlink field and in the report from the table i want view the hyperlink, so i need to write a event procedure to open the hyperlink when a text box is clicked in the...
2
by: Jewel8368 | last post by:
Hi I have a subreport in the report footer of a report. When viewed in report view the subreport and data appear. In print preview only the subreport text label appears. There are additional...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.