Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problems with User entered date ranges 2

Status
Not open for further replies.

JamieF

Technical User
Dec 1, 2000
10
US
I have created a report that prompts the user to enter a starting and ending date so the query can select records in that range. The header of the report includes the date range in the title. If there no records in the range, the report is blank (correct) but the header prints out for the dates "Error#". Is there any way to correct this? Also, I would like to be able to allow the user to optionally hit return on the end date and have the date default to todays date. Can this be done? Thanks!
 
To eliminate the error in the display of date in the header, you would need to reference the date from a source which is not the query. The reason you get an error is simply that when the query returns no records, the record (& thus the date field in the query) doesn'y exist. Place the dates in (?hidden?) text boxes on a/the form which you launch the reprt form. Use these as the source for the report heder dates.

The second one is almost the same. You should add a command to a/the form which is used to launch the report(s). ALWAYS require the user to 'click' this command to get the report - however when it is clicked, do any validation checks necessary (such as setting the end date to the current date if the end date text box is empty (or has anything which is no of date type) before opening the report.

I know it 'looks like' a lot of effort, however the reports (output) of your app is one of the primary interfaces users (and evaluators) see. It is important that this ALWAYS looks professional. When using Ms. Access, I always set up a seperate reporting section (usually a seperate form with a tab control) which presents the user with a report selection screen. the options (parameter selections) appropiate to the selected report and other selections as appropiate. The parameter selections usually have certain default selections set up, which may be changed by the user, however the more important aspect is that all parameters are 'validated' before launching the report.



MichaelRed
mred@duvallgroup.com
There is never time to do it right but there is always time to do it over
 
How would you like to inform the user there is no data for the report and then just not run it altogether? There is an event for your report call On No Data. Add the following to this event procedure.

...
MsgBox "Currently there is no data to match your criteria.", vbOKOnly, "Information"
Cancel = True
...
 
I used Jerry's advice for the On No Data event. However, when I call the report using this procedure...

Sub RunReport(strReportName As String)
DoCmd.OpenReport strReportName, acPreview
End Sub

I get a run-time error..."The OpenReport action was canceled."

What am I missing?

Thanks.

 
I found the answer in another forum...thanks to raskew...

Sub RunReport(strReportName As String)
On Error Resume Next
DoCmd.OpenReport strReportName, acPreview
If Err = 2501 Then Err.Clear
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top