don't won't report to open if message box appears saying no data for report

I started a new job 3 weeks ago and I was given a problem of removing #error when no data is available . I solved this by using "On No Data " event to use a message box to inform the user but now after clicking "OK" it says run time error "2501" " The OpenReport event was canceled do I need a " and if " or some such thing ?
Kirk saintSoftware Designer(Trainee)Asked:
Who is Participating?
 
Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:
In the code that calls the report you must add an error handler and check for error 2501.  If it’s encountered then you just ignore it.

Jim
0
 
Kirk saintSoftware Designer(Trainee)Author Commented:
yes tried that but it keeps going to a separate open event in another part of the code
0
 
Kirk saintSoftware Designer(Trainee)Author Commented:
0
 
Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:
In your Command4 procedure:

At the  start of the procedure:

  On Error Goto Error_Procedure

at the bottom,  add this:

Exit_Procedure:

     Exit Sub

Error_Procedure:
    If err.number <>2501 then
        Msgbox  err.number & " - " & err.description
   End If

   Resume Exit_Procedure

 
 So if you get an error in procedure other than 2501, you'll get a message box.   If you get 2501 because the report open was canceled (due to no data), it will be ignored.

  I would have marked up the code itself, but you posted it as an image.   In the future, when posting code, copy/paste it right in to the comment and use the "code" option so it's formatted.   That will make it easier for you and everyone else in working with it.

Jim.
0
 
Kirk saintSoftware Designer(Trainee)Author Commented:
well thanks but it does appear that there are more problem then what I stated above . like it will return some results for the time period but when I go into design view then into preview layout it adds more results that where not in the first . so getting the correct results is my first problem .
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.