"No data for this time period"

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a filter form based off of a parameter query where the user enters
certain criteria including start and end date to generate various reports.
There's a "run report" command button that generates the report once they've
made their selections. If there's no data for that particular time frame,
the report opens with #Error messages, etc. How would I add code to the
button so that a message box will pop up with "No Data Available for this
time period" instead of opening the report, and then upon clicking OK on the
message box, return to the filter form to enter another query. THANKS!!!
 
Reports have a No Date event. Put a Message Box in that event to tell the
user no data was found for the time period entered.
 
I have a filter form based off of a parameter query where the user enters
certain criteria including start and end date to generate various reports.
There's a "run report" command button that generates the report once they've
made their selections. If there's no data for that particular time frame,
the report opens with #Error messages, etc. How would I add code to the
button so that a message box will pop up with "No Data Available for this
time period" instead of opening the report, and then upon clicking OK on the
message box, return to the filter form to enter another query. THANKS!!!

1) Add error handling to the command button on the form.

On Error GoTo Err_Handler
DoCmd.OpenReport "YourReport", acViewPreview

Exit_ThisSub:
Exit Sub
Err_Handler:
If Err = 2501 then
Else
MsgBox "Error " & Err.Number & " " & Err.Description
End If
Resume Exit_ThisSub
==========

Then Code the Report's OnNoData event:

MsgBox "No Data Available for this time period."
Cancel = True

That should do it.
 
OOPs!
Thans, fredg, I forgot the Cancel part.
However, I don't think that you need the error handler if you trap the No
Data event.
 
Hi Klatuu

Yes, you do. If you cancel the opening of a report by setting Cancel = True
in *either* Report_Open or Report_NoData, then the OpenReport method will
raise a 2501.
 
You are correct. I could not remember specifically. Interestingly enough,
DoCmd.Close does not.

Graham Mandeno said:
Hi Klatuu

Yes, you do. If you cancel the opening of a report by setting Cancel = True
in *either* Report_Open or Report_NoData, then the OpenReport method will
raise a 2501.
--
Cheers!

Graham Mandeno [Access MVP]
Auckland, New Zealand

Klatuu said:
OOPs!
Thans, fredg, I forgot the Cancel part.
However, I don't think that you need the error handler if you trap the No
Data event.
 
Thanks guys. I'll give those a try!!!
Appreciate all the help everyone offers this site... its invaluable!!
--
Patti


Klatuu said:
You are correct. I could not remember specifically. Interestingly enough,
DoCmd.Close does not.

Graham Mandeno said:
Hi Klatuu

Yes, you do. If you cancel the opening of a report by setting Cancel = True
in *either* Report_Open or Report_NoData, then the OpenReport method will
raise a 2501.
--
Cheers!

Graham Mandeno [Access MVP]
Auckland, New Zealand

Klatuu said:
OOPs!
Thans, fredg, I forgot the Cancel part.
However, I don't think that you need the error handler if you trap the No
Data event.

:

On Tue, 14 Feb 2006 12:23:27 -0800, PattiP wrote:

I have a filter form based off of a parameter query where the user
enters
certain criteria including start and end date to generate various
reports.
There's a "run report" command button that generates the report once
they've
made their selections. If there's no data for that particular time
frame,
the report opens with #Error messages, etc. How would I add code to
the
button so that a message box will pop up with "No Data Available for
this
time period" instead of opening the report, and then upon clicking OK
on the
message box, return to the filter form to enter another query.
THANKS!!!

1) Add error handling to the command button on the form.

On Error GoTo Err_Handler
DoCmd.OpenReport "YourReport", acViewPreview

Exit_ThisSub:
Exit Sub
Err_Handler:
If Err = 2501 then
Else
MsgBox "Error " & Err.Number & " " & Err.Description
End If
Resume Exit_ThisSub
==========

Then Code the Report's OnNoData event:

MsgBox "No Data Available for this time period."
Cancel = True

That should do it.
 
Thanks guys. I'll give those a try!!!
Appreciate all the help everyone offers this site... its invaluable!!
--
Patti


Klatuu said:
You are correct. I could not remember specifically. Interestingly enough,
DoCmd.Close does not.

Graham Mandeno said:
Hi Klatuu

Yes, you do. If you cancel the opening of a report by setting Cancel = True
in *either* Report_Open or Report_NoData, then the OpenReport method will
raise a 2501.
--
Cheers!

Graham Mandeno [Access MVP]
Auckland, New Zealand

Klatuu said:
OOPs!
Thans, fredg, I forgot the Cancel part.
However, I don't think that you need the error handler if you trap the No
Data event.

:

On Tue, 14 Feb 2006 12:23:27 -0800, PattiP wrote:

I have a filter form based off of a parameter query where the user
enters
certain criteria including start and end date to generate various
reports.
There's a "run report" command button that generates the report once
they've
made their selections. If there's no data for that particular time
frame,
the report opens with #Error messages, etc. How would I add code to
the
button so that a message box will pop up with "No Data Available for
this
time period" instead of opening the report, and then upon clicking OK
on the
message box, return to the filter form to enter another query.
THANKS!!!

1) Add error handling to the command button on the form.

On Error GoTo Err_Handler
DoCmd.OpenReport "YourReport", acViewPreview

Exit_ThisSub:
Exit Sub
Err_Handler:
If Err = 2501 then
Else
MsgBox "Error " & Err.Number & " " & Err.Description
End If
Resume Exit_ThisSub
==========

Then Code the Report's OnNoData event:

MsgBox "No Data Available for this time period."
Cancel = True

That should do it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top