Understand how, when and why to hide fields in a report during runtime.
MS Access reports provide users with plenty of options and features to play with. A lot of them can be exercised using simple commands or buttons, whereas others can be a bit complicated and might involve use of VBA code. If you are a regular Access user, using the VBA code might not be a challenge for you, but for those who are still trying to figure out how to make the best possible use of the application, VBA might come as a big challenge.
In this article we would be learning ways to hide sections in a report during runtime using VBA code. For those who plan to run away from the article fearing VBA, please note, this is going to involve minimal usage and mention of VBA. And the code that you will be using will require the very basic knowledge of VBA and nothing too complicated.
Hiding Report Sections
When we are using MS Access and creating reports, there would seldom be a requirement for us to hide any given section of the report. As the sole purpose of the report is to summarize; and to hide parts of the summary rarely makes sense. But there can be situations where you need to include some extremely crucial programs within your report, so that any user who wishes to study it can get access to it. But this would not be something that would be of use or interest to all readers of the report. So here you might want to hide the program, and make it visible only when commanded.
Follow these steps to hide section in your report at runtime.
- The very first thing that you are going to need access to is a sample report. For this, you need to import tables from the sample database, and place them in the sample report.
- Once your sample report is ready, you need to open it in the Print Preview, and select all the fields that you wish to hide. To be able to hide these fields, you will need a basic VBA code.
- This code then needs to be copied in the Report Module. Now close VBA window, and get back to the Design View in your report. You can toggle between windows using the Alt + F11 keys.
- In the Detail Section of your report, open Property Sheet, and select On Format Event Property.
- Now you will be able to see your entry, this indicates that the code you pasted is running on Format Event Property
There are two other Events for printing and previewing the report, you can select those as well.
- Save your report and then open it with Print Preview.
- Now you need to check if the fields you were trying to hide have actually hidden or not. You need to check here for the report lines that are associated with the targeted fields.
- Your fields would now be successfully hidden.
While working on MS Access databases, one should always exercise caution and not bloat up the system with unnecessary data. In case you end up with a corrupted database, immediately seek help of a professional tool to repair mdb database files.
Vivian Stevens is a data recovery expert in DataNumen, Inc., which is the world leader in data recovery technologies, including corrupt mdf and excel recovery software products. For more information visit www.datanumen.com