Learn Microsoft Access Advanced Programming Techniques, Tips and Tricks.

Progress Meter


When we process a large volume of data for MS-Access Reports it may take a few minutes to several minutes to complete, depending on the transaction volume involved. The transactions are organized and processed through Select Queries, and Action Queries, sequencing the process through Macros and VBA routines to arrive at the final Report Data.  If you have Action Queries that pull data from Select, Crosstab Queries, and if a large volume of transactions is involved, it may take longer than the Normal Queries to filter for output.

In all these situations it will be difficult for the user to know how long the whole process will take to complete the task. After running the process a few times the user may get a rough idea as to how long it will take to finish. 

Normally at the beginning of a lengthy process, the Mouse Pointer can be turned on into an Hourglass shape (Docmd.Hourglass True) indicating that the machine is engaged, and can be turned it off at the end of the process. But, this method will not give an exact indication as to when the process will be over.  

If it takes more than the usual running time, depending on other factors, like an increase in the volume of transactions or due to busy network traffic and so on, it is difficult to determine whether the process is really running or it is a machine hang up issue.

The Quick Solution

When we run several Action Queries in a chain from within a Macro, MS-Access displays a Progress Meter for a brief moment for each Query on the Status Bar. If the Status Bar is not visible you can turn it on. Select Options from the Tools menu, and select View Tab on the displayed Dialog Control. Put a check-mark in the Status Bar option, under Show Options Group. But it will not give an overall time indicator for the full process.

A Better Approach.

We will make use of the Progress Meter for our data processing tasks more effectively and will look into more than one method. The users of our Application can relax during the whole process and take little time off to flip through the Weekly Magazine with an occasional glance at the Progress Meter.

  1. Displaying the Progress Meter on the Status Bar
  2. Displaying the Progress Meter on a Form
  3. Usage of a transaction countdown method.

Usage of Progress Meter on the Status Bar.

We will use the Order Details Table from the Northwind.mdb sample database for our example and write a VB Routine to calculate the Extended Price on each entry in this Table. If you have not already imported this Table for our earlier examples you may do it now. If you don't know the exact location of this file on your machine, please visit the Page Saving Data on Forms not in Table for references.

  1. Import the Order Details Table from Northwind.mdb sample Database.
  2. Open the Order Details Table in Design View and add a new field with the name ExtendedPrice (Field Type: Number, Field Size: Double) at the end of the existing fields. We will write a program to calculate the extended price of each record and update this field.
  3. Design a simple form similar to the one shown below with a Command Button on it. We will modify this Form for our next example also.
  4. Click on the Command Button and display the Property Sheet (View -> Properties).
  5. On the On Click Property type =ProcessOrders() to run the program, which we are going to write now. Do not forget the equal sign in =ProcessOrders(), otherwise, MS-Access will take it as a Macro name.
  6. Close the form and save it with the name ProgressMeter.

    Usage of SysCmd().

  7. Copy and Paste the following Code into a Global VB Module of your Project and save it.
    Public Function ProcessOrders()
    Dim db As Database, rst As Recordset
    Dim TotalRecords As Long, xtimer As Date
    Dim ExtendedValue As Double, Quantity As Integer
    Dim Discount As Double, x As Variant, UnitRate As Double
    On Error GoTo ProcessOrders_Err
    DoCmd.Hourglass True
    Set db = CurrentDb
    Set rst = db.OpenRecordset("Order Details", dbOpenDynaset)
    TotalRecords = rst.RecordCount
    Do While Not rst.EOF
      With rst
        Quantity = ![Quantity]
        UnitRate = ![UnitPrice]
        Discount = ![Discount]
        ExtendedValue = Quantity * (UnitRate * (1 - Discount))
        ![ExtendedPrice] = ExtendedValue
        If .AbsolutePosition + 1 = 1 Then
           x = SysCmd(acSysCmdInitMeter, "process:", TotalRecords)
          'a delay loop to slow down the program       
          'to view the Progress Meter in action.      
          'you may remove it.      
          xtimer = Timer
          Do While Timer < xtimer + 0.02
          x = SysCmd(acSysCmdUpdateMeter, .AbsolutePosition + 1)
        End If
      End with
    x = SysCmd(acSysCmdRemoveMeter)
    DoCmd.Hourglass False
    MsgBox "Process completed.", , "ProcessOrders()"
    Set rst = Nothing
    Set db = Nothing
    Exit Function
    MsgBox Err.Description, , "ProcessOrders()"
    Resume ProcessOrders_Exit
    End Function
  8. Open the ProgressMeter Form in normal view and click on the Command Button. You will see the Progress Meter slowly advancing and when it reaches the end of the bar a message will appear announcing that the work is complete.

We have used MS-Access's built-in Function SysCmd() to update the Progress Meter on the Status Bar. When the Function is first called, the Maximum Number of Records in the File is passed as the third parameter to the function to initialize the Progress Meter. Subsequent calls are made with the current record number to update the Meter with the current status. MS-Access calculates a percentage of the current number of records processed based on the Total Records that we have passed to the InitMeter step and updates the Progress Meter. The blue-colored indicator on the Progress Meter may advance one step, only after processing several records depending on the total number of records in the file.

A delay loop is built into the Code to slow down the program and view the Progress Meter in action. You may remove these lines when using them in your Project.

Need a Better Method

We cannot use this method when we sequence our process steps in Macros involving Queries. Because, when each Action Query is run MS-Access uses the Status Bar to display the progress of each and every query separately overwriting our overall process time meter. We have to devise a method of our own to do this.

Next, we will see the usage of a Progress Meter on a Form, for the Data Processing steps sequenced through Macro.


Download Access2007 Version

Download Access2003 Version


No comments:

Post a Comment

Comments subject to moderation before publishing.




Post Feed


Popular Posts

Blog Archive

Powered by Blogger.


Forms Functions How Tos MS-Access Security Reports msaccess forms Animations msaccess animation Utilities msaccess controls Access and Internet MS-Access Scurity MS-Access and Internet Class Module External Links Queries Array msaccess reports Accesstips WithEvents msaccess tips Downloads Objects Menus and Toolbars Collection Object MsaccessLinks Process Controls Art Work Property msaccess How Tos Combo Boxes Dictionary Object ListView Control Query VBA msaccessQuery Calculation Event Graph Charts ImageList Control List Boxes TreeView Control Command Buttons Controls Data Emails and Alerts Form Custom Functions Custom Wizards DOS Commands Data Type Key Object Reference ms-access functions msaccess functions msaccess graphs msaccess reporttricks Command Button Report msaccess menus msaccessprocess security advanced Access Security Add Auto-Number Field Type Form Instances ImageList Item Macros Menus Nodes RaiseEvent Recordset Top Values Variables Wrapper Classes msaccess email progressmeter Access2007 Copy Excel Export Expression Fields Join Methods Microsoft Numbering System Records Security Split SubForm Table Tables Time Difference Utility WScript Workgroup database function msaccess wizards tutorial Access Emails and Alerts Access Fields Access How Tos Access Mail Merge Access2003 Accounting Year Action Animation Attachment Binary Numbers Bookmarks Budgeting ChDir Color Palette Common Controls Conditional Formatting Data Filtering Database Records Defining Pages Desktop Shortcuts Diagram Disk Dynamic Lookup Error Handler External Filter Formatting Groups Hexadecimal Numbers Import Labels List Logo Macro Mail Merge Main Form Memo Message Box Monitoring Octal Numbers Operating System Paste Primary-Key Product Rank Reading Remove Rich Text Sequence SetFocus Summary Tab-Page Union Query User Users Water-Mark Word automatically commands hyperlinks iSeries Date iif ms-access msaccess msaccess alerts pdf files reference restore switch text toolbar updating upload vba code