473,406 Members | 2,843 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,406 software developers and data experts.

Dont show report when invalid date is entered?

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
7 1861
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
<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
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
<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
Do you know where in access i need to trap for the OpenReport action
canceled?

Nov 13 '05 #6
<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
hey how can we access Gmail please tell meh?

Nov 13 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Dan Williams | last post by:
Apologies for the cross-post but i thought i'd aim for the largest audience possible. I have a web site that users have to register to with their email address. The site then emails the user...
5
by: Jim Fox | last post by:
I have a report that I created that has no data, just boxes, lines and one date field not tied to anything. Basically this report will just print pages according to the dates you entered. Then...
2
by: Sara | last post by:
I have followed instructions on the http://allenbrowne.com/tips.html for limiting a report to a date range. At the bottom there is a note that says You will end up using this form for all sorts...
9
by: MLH | last post by:
Trouble is, it doesn't happen every time. Yesterday, for example, it happened only once and not again afterward. Some days ago, a similar situation. Today, well - I tried 7 times straight to open...
3
by: Scott | last post by:
I need to take the median from a field of records in a report. Can someone shed the light how to do it. Thanks, Scott
13
by: alive84 | last post by:
Hi there, I have a two problems concerning option button values on a report and data report creator reports. The situation: I have three option value boxes two have 3 option and one has...
3
by: Fred's | last post by:
Hi Folks, I have a report which the record source is a query name: Query3 and in my Query3 I have this parameter "between And ". Therefore, when I open my report, it will ask for a Start Date...
14
ollyb303
by: ollyb303 | last post by:
Hi, I am trying to create a dynamic crosstab report which will display number of calls handled (I work for a call centre) per day grouped by supervisor. I have one crosstab query (Query1) which...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.