Create MS Access Macro an to Print a Report

0
3

With no programming whatsoever it is possible to create an MS Access macro to automate a vast range of tasks in your MS Access database. Many people new to MS Access find programming difficult and would like a way of adding more power to their databases. A macro is the answer.

Instead of using menu and toolbar commands it is possible to assign a macro to a command button, which will require one click to print the report.

Depending on the version of Access you are using some of the naming may be slightly different to how it is described in this article, but essentially the meaning is the same and you will be able to find your way around things.

First go to the macro designer and enter the name of a brand new MS Access macro in the column called 'Macro Name'. For example I could use the name 'PrintInvoiceReport'. Now click the drop down arrow on the actions column and select the action called 'OpenReport'.

Go to the bottom of the screen and you will see a box for entering action arguments. You will need to enter the report you wish to open. Now select the view you wish to see the report in. For example, if you want to preview it only then select the print preview option otherwise select the print option.

The comment column is optional, but it can be useful for entering what the macro is actually doing. Not only is it helpful to yourself, but if you have other developers using the database they will have a clear indication of the purpose of the macro.

Now all you need to do is save the macro and give it a name. Give it a different name to the name you entered in the designer. For now call it 'Macro1', you can always rename it later.

The next step involves wiring up the Microsoft Access macro to a command button. If you do not have a particular form you wish to use then create a blank one and go to the design view. Now use the wizard to create a command button and drag it to the form.

Once the wizard starts you need to select the option called miscellaneous from the left hand box. Then select the run macro option from the right hand box. Click the next button to move on. Now select the macro to run and click next or finish to reach the end.

Now run the form and click the button. You should find your report now opens in the view you selected.

The MS Access macro is an extremely powerful tool for automating your databases. Whenever you need to perform tasks that need automating you should forget about writing endless lines of program code and look at the MS Access macro. There are not many books dedicated to the subject, but you can find many tutorials online. Macros can be applied to the different database objects such as forms and reports. Remember there is no error checking in macros and you should take care when creating them.

Recommended for you

Leave a Reply