Access JumpStart 2.0 | Blog

A Rapid Development Framework for Microsoft Access

Today I was working on a file importer in Access again for my customer. This importer is using the technique of throwing an error as discussed in my previous message. My next task was to display a report if the file being imported raised the error and allow the customer to print it or close it. The report itself contains the error message and the information needed that tripped the error condition (showing all part numbers without pricing records from the file being imported). This stalls right in the middle of my importing routine, and I wanted it to pause so that it wouldn’t continue processing the next file and then mess up the current report with new information.

So I catch the application error in an error handler and then if the error number is the one expected, I run a

Resume DisplayReport

command to go to a label in the routine to get out of the error condition and show the report.

I wanted buttons to appear on the report to make it obvious that they could print it or close it, but I didn’t want the buttons to appear when they printed the report. I set the buttons Show On property to “Screen Only”. However, if you are going into print preview view, it will also not show the buttons because it is showing the report as it will be printed.

Therefore I had to open the report in “Report View” instead, which has no pagination, but that’s fine. I ended up making the page footer “Screen Only” as well so that it wouldn’t print the page footer at the end of the report view data.

Next I had a problem with the Report View opening only in a tab. My Access program was set in tab view and I didn’t have the luxury of changing it for the user. So I was able to instead set properties in the report object itself to Popup: True, and Modal: True (which prevents the user from switching focus away from it).

Finally, if the command to print the report (which brought up the print dialog) was canceled, the program displayed an error. Error 2501 will display when starting to open an object and it gets canceled. It can happen with Forms as well, but in this case it was the system print dialog that was being canceled out of. So I set up the error handler to catch that case too and made sure if the error was 2501 it would not display that message to the user.

So after a lot of trial and error I made it through the above steps and got the report and system functionality working just as I needed it to in a way that will be very helpful to the users. Whew! It took a lot more effort than anticipated!