By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,148 Members | 759 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,148 IT Pros & Developers. It's quick & easy.

Dont show report when invalid date is entered?

P: n/a
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 [Date]. The report is created fine when a valid (a date that is in
the table) is entered. However, is it possible to display a message to
the user when the date is not found and then not display the report?

Many thanks
Simon

Nov 13 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
I guess i need an if statement when i click a button on a form. Not
sure though as am new to Access.

Nov 13 '05 #2

P: n/a
<si************@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
I guess i need an if statement when i click a button on a form. Not
sure though as am new to Access.


You could use the report's NoData event to pick this up:

Private Sub Report_NoData(Cancel As Integer)
MsgBox "No matching records"
Cancel = True
End Sub
Just note that if you use a button to open the report and the open event is
cancelled, you get an error which you should trap for.
Nov 13 '05 #3

P: n/a
Hi that works great thanks.

But i get an error as you said which says the OpenReport Action was
canceled. And then doesnt re ask the user for a date.
Ideally i'd like this not to display and go back to the input screen.
Is this what you meant by trapping the error?

Sorry am new to access.

Cheers.

Nov 13 '05 #4

P: n/a
<si************@gmail.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
Hi that works great thanks.

But i get an error as you said which says the OpenReport Action was
canceled. And then doesnt re ask the user for a date.
Ideally i'd like this not to display and go back to the input screen.
Is this what you meant by trapping the error?

First off, "Date" is a reserved word in VBA, so consider changing this to
vDate or something like that.

IIRC the error number for this particular error is 2501, so to trap for it
you would have something like:

On Error GoTo Err_trap

Your code goes here

Err_trap:
If Err.Number=2501 Then Exit Sub

You'd need to design a form as a dialog box for criteria entry if you want
to avoid having to start from scratch every time there's no data. Keep the
form open beneath your report and it will still be there when the report is
closed or when the On No Data event fires. It can then be either re-used or
closed as appropriate.

HTH - Keith.
www.keithwilby.com
Nov 13 '05 #5

P: n/a
Do you know where in access i need to trap for the OpenReport action
canceled?

Nov 13 '05 #6

P: n/a
<si************@gmail.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
Do you know where in access i need to trap for the OpenReport action
canceled?


If the button is named cmdReport, then the coding for the OnClick event
would be something like:
Private Sub cmdReport_Click()

On Error GoTo Err_Handler

DoCmd.OpenReport "MyReport", acViewPreview

Exit_Handler:
Exit Sub

Err_Handler:

Select Case Err.Number

Case 2501
' The report has been cancelled due to no data
' The report's coding shows the message,
' so no need for another one here.

Case Else
MsgBox Err.Description, vbExclamation, "Error No: " & Err.Number

End Select

Resume Exit_Handler

End Sub
' Assuming that the NoData code for the report is as before:
' Private Sub Report_NoData(Cancel As Integer)
' MsgBox "No matching records"
' Cancel = True
' End Sub


Nov 13 '05 #7

P: n/a
hey how can we access Gmail please tell meh?

Nov 13 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.