Microsoft Access
  Home arrow Microsoft Access arrow Page 4 - Getting to Know Microsoft Access, Part 9: ...
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

Getting to Know Microsoft Access, Part 9: Macros
By: Sage Adams
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 18
    2005-03-22

    Table of Contents:
  • Getting to Know Microsoft Access, Part 9: Macros
  • Macros
  • Debugging
  • Getting Fancy with Macros

  • 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


    Getting to Know Microsoft Access, Part 9: Macros - Getting Fancy with Macros


    (Page 4 of 4 )

    You can easily add conditions (which make the macro run only under specific criteria) to your macros. You apply a condition to a certain action in the macro sheet and when you run the macro, if the condition is not met, the action is skipped and the next action in the sequence is run. You can make conditions apply to multiple sequential actions by putting an ellipsis (…) in the next action's Condition column.

    You can also create If…Then…Else structures in macros using conditions. Add the Conditions column to the macro sheet by selecting the View | Conditions menu option. You cannot use SQL expressions in conditions.

    To force a choice between two actions you can use two different versions of the same condition. Here's an example:

    IsNull("First Name") The action runs if the field is empty

    Not IsNull("First Name") Runs if the field is not empty

     

    You can assign macros to specific event properties in your forms and reports. All you have to do is set the event property of the corresponding control to the name of the macro.

    Some of the more common macro-related tasks include the following: validation, filtering, message boxes, and setting values. Let's start with validation. Of course, you could set a validation rule in the control you want validated. However, more complex data validation requires macros. Use a macro instead of a validation rule if any of the following is required for proper validation:

    • The validation refers to another form's controls.
    • Multiple error messages should be able to be displayed for different types of errors.
    • The rule utilizes conditions based on more than one value.
    • The user should be able to override the rule.
    • The validation rule is generic and can be used for multiple forms.

    You can use a filtering macro to, for example, set buttons that display different, filtered, data sets. You can do this by using an option group for the buttons. Each button, when pressed, returns a value. This value in turn is used as a condition for the ApplyFilter action. The Where Condition argument specifies the filter you want to use.

    Use the MsgBox action to create message boxes in response to certain actions. Use it to display warnings, alerts, and so forth. You can set the Message, Beep, Type, and Title options for this action. Message is the message to display; Beep is just a sound and can be set to either yes (a sound) or no (no sound); Type sets the icon to use (such as the red circle with an x); and Title sets the message box's title bar.

    Use the SetValue action to set values. SetValue has two arguments: Item and Expression. Item refers to the field you want to set the value of, and the Expression argument sets the new value for the field.

    The last thing I'll mention in this week's lesson is AutoExec. AutoExec is a file that runs when a program opens. You can create an AutoExec macro that runs when you open the database by simply saving your macro as "AutoExec"; the database can have only one AutoExec macro.


    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.

       · Hi,overall content of article is good,but where r the examples? In detail...
     

    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 1 hosted by Hostway