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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create Form for selection criteria for Report 2

Status
Not open for further replies.

was1

Technical User
Aug 10, 2005
31
US
I'm trying to create 1 report that the end user can pick and choose which criteria they would like. There will be around 5 different fields (combo boxes, text fields, data ranges). I don't have any VB knowledge. Can it be down in a macro??
 
Set the On No Data property of the report to [Event Procedure]. In the event procedure, add the following code:

msgbox "no data exists for the criteria specified"
Cancel = true

Note that because you set Cancel to True, the code that opened the report will need to trap the error it produces.
 
Thanks, FancyPrarie.

I understand in an intuitive sense what you mean about needing to trap the error - I set the On NoData property and did get the message box (thanks to your instructions) as well as the ensuing error (run-time error 2501).

I think that I need to modify the event procedure in which I call your BuildWhere function...because that is how I opened the report (using OpenReport...BuildWhere(Me)...code).

Is that where I need to add some code to trap the error? I did hunt through the FAQ and I found:

Code:
if dataerr = 2113 then
  ' wrong datatype, I think
  msgbox "you entered blah blah"
  response = acdataerrcontinue
  ' dont' display the custom message
end if

The FAQ implied that I should add this to the On Error property of a form. Now, I'm running BuildWhere to open my report, so does that mean that instead I need to add code like this to BuildWhere? I'm hesitant to mess with that since it is working so beautifully.

If you have tired of helping me, just say so and I'll find another (inelegant) solution. I'm not a programmer so I may be straying into problems that I can't resolve.

Thanks for your (honest) answer.

 
Your code should look something like this:

On Error GoTo ErrHandler
....
....
Docmd.OpenReport "YourReportName",,,BuildWhere(Me)
....
....
ExitProcedure:
Exit Sub

ErrHandler:
if (err.number = 2501) then
Resume Next
Else
msgbox err.number & vbcrlf & err.description
Resume ExitProcedure
End If
 
Hi, FancyPrarie ~

This worked like a charm. [red]Many thanks![/red]

CJaneCode
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top