Avatar of Frank Freese
Frank FreeseFlag for United States of America

asked on 

No data found in report

Experts,
If there is no data when trying to print a report in the NoData event I execute the following:

MsgBox "No Data Found!", vbExclamation, "No Data Found"
rstReport.Close

Here's my questions: What is rstReport for and can I continue my code with

Docmd.OpenForm "frmMainMenu"

after rstReport.Close
Microsoft Access

Avatar of undefined
Last Comment
TextReport
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

you don't need that rstReport.Close


Private Sub Report_NoData(Cancel As Integer)

MsgBox "No Data Found!", vbExclamation, "No Data Found"
cancel=true

end sub
Avatar of JohnSingleton
JohnSingleton

I'd replace it with me.report.close

put it before the rstReport.close line


-John

Private Sub Report_Open(Cancel As Integer)
MsgBox "No Data Found!", vbExclamation, "No Data Found"
Docmd.OpenForm "frmMainMenu" 
DoCmd.Close acReport, Me.Name, acSaveNo
 
End Sub

Open in new window

with cancel=true  the report will not be printed or previewed
Avatar of TextReport
TextReport
Flag of United Kingdom of Great Britain and Northern Ireland image

I'm with Capricorn1 here Cancel=True will cancel the OnNoData event and not open the report.

You can put in the Docmd.OpenForm "frmMainMenu" if you wish either before or after the Cancel line, however, you are probably opening the report from the menu. If you are and you are using VBA to open the report the you will receive an error in the procedure that opens the report, the error will be a 2450 (I think) that you will need to trap or you will receive another error message.

Cheers, Andrew
Avatar of Frank Freese
Frank Freese
Flag of United States of America image

ASKER

Therefore, in the report event NoData this would work:

MsgBox "No Data Found!", vbExclamantion, "No Data Found"
Cancel = True
Docmd OpenForm "frmMainMenu"

Avatar of TextReport
TextReport
Flag of United Kingdom of Great Britain and Northern Ireland image

Yes except it is DoCmd.OpenReport "frmMainMenu"
Avatar of Frank Freese
Frank Freese
Flag of United States of America image

ASKER

confused...
after cancel = true i am looking to return to the Main Menu
fh_freese,

where did you open the report ?

if on the main menu form..
this codes are all you nee

Private Sub Report_NoData(Cancel As Integer)

MsgBox "No Data Found!", vbExclamation, "No Data Found"
cancel=true

end sub


SOLUTION
Avatar of TextReport
TextReport
Flag of United Kingdom of Great Britain and Northern Ireland image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Frank Freese
Frank Freese
Flag of United States of America image

ASKER

I open the report with a command button as follows:

Docmd.OpenReport "rptDailyScrap", acViewPreview
Docmd.Close acForm, "frmScrapReports"

If no data then it appears I can do:

MsgBox "No Data Found!", vbExclamantion, "No Data Found"
Cancel = True
Docmd.OpenForm "frmMainMenu"



ASKER CERTIFIED SOLUTION
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of Frank Freese
Frank Freese
Flag of United States of America image

ASKER

thank you..much appreciated
Avatar of TextReport
TextReport
Flag of United Kingdom of Great Britain and Northern Ireland image

If your report contains No Data then your command button will error on the DoCmd.OpenReport line, this error is normal but you will have to handle the error as currently it will not run the DoCmd.Close command in your command button.

Do you have an error handler in the Command Button Code, The Error Handler will be an On Error command.

Cheers, Andrew
Microsoft Access
Microsoft Access

Microsoft Access is a rapid application development (RAD) relational database tool. Access can be used for both desktop and web-based applications, and uses VBA (Visual Basic for Applications) as its coding language.

226K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo