Catch error on open report

DoCmd.openReport "ThisWeekPayReport", acViewReport, , , acDialog

The above command is fired by a button on a form. The data source of the report has a criteria of employee number. Once the button is clicked Access opens a dialog box titled "Enter Parameter Value".  If an incorrect number is entered how can I catch it?

Is there some kind of an OnError condition that I could place the DoCmd inside of that would catch it if an incorrect number was entered?



Gary SamuelsPlant ManagerAsked:
Who is Participating?
 
Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:
<<If an incorrect number is entered how can I catch it?>>

  You can't.  What you need to do is setup a form to collect the employee number using something like a combo, so they are forced to pick a valid number.

  Then call the report and have it's recordsource look to the form control to get the correct value. i.e.

  =Forms![<myFormName>]![<myEmployeeComboControlName>]

 replacing everything in the <> (and including them) with the correct values.

JimD.

 
0
 
Gary SamuelsPlant ManagerAuthor Commented:
I was afraid of that.

Thanks
0
 
Gary SamuelsPlant ManagerAuthor Commented:
If I wanted to use a textbox and verified the input.
Could I add the Filter and Where parameters to the DoCmd.openReport statement to accomplish the same thing?

Something like:
DoCmd.openReport "ThisWeekPayReport", acViewReport,Filter=[EmployeeNumber] ,WHERE=textbox.value , acDialog
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.