Printing forms from Microsoft Access

Added on: Wednesday 17th March 2010

I have many clients who occasionally like to print out a form record from their databases. Obviously they have reports for the information they regularly print out but sometimes its useful to take a 'screengrab' of the current record they are viewing.

The problem is that often although the form is displaying one record it will actually print out all the records in the underlying recordsource which can mean the whole table.

I did a quick search on the Internet and was surprised to find that almost all results suggest creating a report and then using the 'where condition' of the OpenReport method so that only the selected record is displayed.

The question is- is it worth creating a report for every form that you might want to print out.

I was surprised that not one solution mentioned actually printing the form itself.

All you need to do is use the PrintOut method and ensure that it only prints one page. The code behind the button is shown below:

DoCmd.PrintOut acSelection, 1, 1

Where acSelection is the print range and the two 1s are the first and last page to print.

There are other tricks you can use too. All objects on the form have a Display When property - by default this is set to Always but if you set it to Screen Only the object won't appear on the printed page. So for example your print button doesn't need to appear on the print.

The header and footer sections of the form also have a Display When property so you can hide these too on the print out.

Finally, you can change the Page Setup for the Form - for example changing the layout to Landscape and reducing the margins - so that the record fits on one page.

There are disadvantages of course - you'll get all the shading or colour of the form - but as a quick and dirty method it works fine and saves building a report.