Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old November 13th, 2005, 11:42 AM
simonmarkjones@gmail.com
Guest
 
Posts: n/a
Default 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

  #2  
Old November 13th, 2005, 11:42 AM
simonmarkjones@gmail.com
Guest
 
Posts: n/a
Default Re: Dont show report when invalid date is entered?

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

  #3  
Old November 13th, 2005, 11:42 AM
Justin Hoffman
Guest
 
Posts: n/a
Default Re: Dont show report when invalid date is entered?

<simonmarkjones@gmail.com> wrote in message
news:1118326122.669133.141330@f14g2000cwb.googlegr oups.com...[color=blue]
>I guess i need an if statement when i click a button on a form. Not
> sure though as am new to Access.[/color]

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.


  #4  
Old November 13th, 2005, 11:42 AM
simonmarkjones@gmail.com
Guest
 
Posts: n/a
Default Re: Dont show report when invalid date is entered?

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.

  #5  
Old November 13th, 2005, 11:42 AM
Keith
Guest
 
Posts: n/a
Default Re: Dont show report when invalid date is entered?

<simonmarkjones@gmail.com> wrote in message
news:1118327812.388746.196490@g49g2000cwa.googlegr oups.com...[color=blue]
> 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?
>[/color]
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


  #6  
Old November 13th, 2005, 11:43 AM
simonmarkjones@gmail.com
Guest
 
Posts: n/a
Default Re: Dont show report when invalid date is entered?

Do you know where in access i need to trap for the OpenReport action
canceled?

  #7  
Old November 13th, 2005, 11:43 AM
Justin Hoffman
Guest
 
Posts: n/a
Default Re: Dont show report when invalid date is entered?

<simonmarkjones@gmail.com> wrote in message
news:1118401242.154319.106600@g44g2000cwa.googlegr oups.com...[color=blue]
> Do you know where in access i need to trap for the OpenReport action
> canceled?
>[/color]

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




  #8  
Old November 13th, 2005, 11:43 AM
webweaver_khries
Guest
 
Posts: n/a
Default Re: Dont show report when invalid date is entered?

hey how can we access Gmail please tell meh?

 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles