Jump Start VBA Skills with MS Access Macros - Creating the second macro
(Page 5 of 5 )
Now I have a table imported into this program for demo purposes. It's called employees. I will create a query from this table called qryEmp (just to limit the columns to a few) and a report based on the query called Employee Report. Now let's create a macro which will open up the report we created. I have not shown all the steps for query and report creation, but you can get them from the ASP Free site under the MS Access sub-heading.
Click on Macro object in the main window and click new to open the macro designer. In the Action column, click on the arrow to pick from the list, Open Report. Add some comments.

The action, OpenReport, requires some arguments. The first argument should be which report, as there could be any number of reports. In the Action Arguments section, click on an empty space in the box Report Name and from the drop-down menu pick the item "Employee Report", which is the only item. There is just this one item now, but if there were many you would get to pick the one you want. Similarly you pick the Preview for the View and Normal for the Window Mode. For now, we are not using the Filter Name and Where Condition, since we want to keep discussion focused on conversion to VBA only. The text area filled with letters in blue accurately describes each item that you focus on, and you should take the time to read it.

Convert this macro to VBA as described earlier in the first macro. Double click this macro in the VB editor and you will see the following code.

Here is one of the important keywords, 'DoCmd'. This command opens up the report we created earlier whenever the macro is run. Highlight DoCmd and hit the key F1; this opens up the next window as shown.

Now you have hit the core of the application object. Experiment by creating various macros, and see how it transliterates to VBA code. This is a good starting point. There are a number of macros, and you can learn a lot of VBA. If you want more, get into the online help screen with its innumerable links to fine grained description, often with fine examples.
Now let's test the macro created. It can be run from the main window with all the objects, or it can be run from the VB Editor after bring up the Function and using the start, pause, and stop icons.

As soon as the macro runs, this report created earlier pops-up in the 'Normal' mode.
Summary
The macro route suggested in this tutorial is a good starting point for learning VBA. Within a short time you could become very productive. The on-line help, and the context sensitive F1 key are invaluable. There is a lot more to macros than what I have shown here, but the basic scheme is the same. This also helps with understanding VBScript and Visual Basic.
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |