Microsoft Access
  Home arrow Microsoft Access arrow Page 5 - Jump Start VBA Skills with MS Access Macro...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Moblin 
JMSL Numerical Library 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
MICROSOFT ACCESS

Jump Start VBA Skills with MS Access Macros
By: Jayaram Krishnaswamy
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 29
    2005-11-08

    Table of Contents:
  • Jump Start VBA Skills with MS Access Macros
  • Creating and running a macro in MS Access: opening the macro designer
  • Creating the first macro
  • Converting this macro to VBA code
  • Creating the second macro

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    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.

       · It's my pleasure to welcome you to read and comment on this article. VBA is a...
       · Is it possible to add a pop up window in Access.fro instance if one has a stock...
       · Does not mean I have a code ready. With DAP you should be able to do this and much...
       · Hello!Not sure where to look for the "steps for query and report creation",...
       · By the quoted text in your question, what I mean is, that I am assuming that I am...
     

    MICROSOFT ACCESS ARTICLES

    - Linking SQL Express 2005 Tables to MS Access...
    - Working with Access Projects in Access 2007
    - Exploring Access 2007
    - Working with Stored Procedures in an MS Acce...
    - Creating and Using Action Queries
    - Creating Data Access Pages with Charts using...
    - Advanced Ideas using VBA
    - VBA Details
    - Updating Records in MS Access
    - Using ADO`s Record Object with URLs
    - Exporting XML from MS Access 2003
    - Importing XML into MS Access 2003
    - On Using Pass-through Queries in MS Access
    - Distributed Queries in MS Access
    - Configuring a Linked Microsoft Access Server...





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway