Learn Microsoft Access Advanced Programming Techniques, Tips and Tricks.

Progress Meter

Introduction.

When processing large volumes of data for Microsoft Access reports, the operation can take anywhere from a few seconds to several minutes, depending on the volume and complexity of the transactions involved. These transactions are typically organized and executed using a combination of Select and Action Queries, orchestrated through Macros or VBA routines to produce the final report output.

If your Action Queries depend on SELECT or CROSSTAB Queries as input sources—particularly when dealing with high transaction volumes—the overall processing time can increase significantly.

In such cases, users may find it difficult to estimate how long the task will take to complete. Over time, with repeated use, they may develop a rough idea of the expected duration.

A common practice is to display the hourglass cursor (DoCmd.Hourglass True) at the beginning of a long-running operation to signal that processing is underway. The hourglass is then reset at the end of the task. However, this visual cue does not provide users with a clear indication of progress or how much time remains until completion.

If the process takes longer than usual—due to factors such as increased transaction volume, heavy network traffic, or other system-related delays—it becomes difficult to determine whether the operation is still actively running or if the system has encountered a hang or failure.

The Quick Solution.

When multiple Action Queries are executed in sequence within a Macro, Microsoft Access briefly displays a Progress Meter on the Status Bar for each query. If the Status Bar is not visible, you can enable it by selecting Options from the Tools menu, navigating to the View tab in the dialog box, and checking the Status Bar option under the Show group. However, this only provides momentary feedback for individual queries and does not indicate the overall progress or estimated time remaining for the entire process.

A Better Approach.

We will explore how to make more effective use of the Progress Meter during data processing tasks by implementing multiple methods. This will allow users of our application to stay informed about the progress, giving them the confidence to momentarily step away or flip through a weekly magazine, while occasionally glancing at the screen to monitor the process.

  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 to demonstrate our example. Our objective is to write a VBA routine that calculates the Extended Price for each entry in this table. If you haven’t already imported the table while working through previous examples, you may do so now. If you're unsure about the exact location of the Northwind.mdb file on your machine, refer to the page Saving Data on Forms Not in Table for guidance.

Steps:

  1. Import the Order Details table from the Northwind.mdb sample database into your project.

  2. Open the table in Design View, and add a new field  ExtendedPrice at the end of the existing fields.

    • Data Type: Number

    • Field Size: Double

  3. Design a simple form with a Command Button on it, similar to the sample shown below. We’ll use and enhance this form for the next example as well.

  4. Assigning the Procedure to the Command Button.

    1. Click on the Command Button to select it.

    2. Open the Property Sheet (choose ViewProperties if it’s not already visible).

    3. Locate the On Click property.

    4. Enter the following expression in the On Click property:

      =ProcessOrders()

      Note: Make sure to include the equal sign (=) at the beginning. Without it, MS Access will interpret the value as the name of a macro instead of a function call.

    5. Close the form and save it with the name: ProgressMeter.

    Usage of SysCmd().
  5. 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)
    rst.MoveLast
    TotalRecords = rst.RecordCount
    
    rst.MoveFirst
    Do While Not rst.EOF
      With rst
        Quantity = ![Quantity]
        UnitRate = ![UnitPrice]
        Discount = ![Discount]
        ExtendedValue = Quantity * (UnitRate * (1 - Discount))
    
        .Edit
        ![ExtendedPrice] = ExtendedValue
        .Update
    
        If .AbsolutePosition + 1 = 1 Then
           x = SysCmd(acSysCmdInitMeter, "process:", TotalRecords)
        Else
          '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
            Doevents
          Loop
    '=================================================
    
          x = SysCmd(acSysCmdUpdateMeter, .AbsolutePosition + 1)
        End If
    
       .MoveNext
      End with
    Loop
    rst.Close
    x = SysCmd(acSysCmdRemoveMeter)
    DoCmd.Hourglass False
    
    MsgBox "Process completed.", , "ProcessOrders()"
    
    Set rst = Nothing
    Set db = Nothing
    
    ProcessOrders_Exit:
    Exit Function
    
    ProcessOrders_Err:
    MsgBox Err.Description, , "ProcessOrders()"
    Resume ProcessOrders_Exit
    
    End Function
  6. Open the ProgressMeter form in Form View and click the Command Button. You will see the Progress Meter gradually advancing across the status bar. Once it reaches the end, a message will appear indicating that the task has been completed successfully.

We have used Microsoft Access's built-in Function SysCmd() to control and display the Progress Meter on the Status Bar. When the function is first invoked, it is passed the total number of records in the table as the third parameter, which initializes the Progress Meter. Subsequent calls to the function supply the current record number, allowing Access to calculate the percentage of records processed and update the meter accordingly.

The blue indicator on the Progress Meter advances in proportion to the percentage of completion. For large datasets, this means the bar may not visibly move with every single record processed, but instead updates after processing a batch, based on the overall total.

A delay loop has been added to the code for demonstration purposes, allowing users to observe the Progress Meter in action. You may remove these lines when incorporating the routine into your actual project for better performance.

Need a Better Method.

We cannot use this method when sequencing process steps through Macros involving Action Queries. This is because, during execution, Microsoft Access automatically updates the Status Bar to display the progress of each individual query, which overrides and interferes with our custom Progress Meter based on SysCmd().

To overcome this limitation, we must devise an alternative method to track the overall progress of the entire process.

In the next section, we will explore how to use a custom Progress Meter on a Form to visually track the progress of data processing steps executed through a Macro.

Download.


Download Access2007 Version



Download Access2003 Version

Share:

No comments:

Post a Comment

Comments subject to moderation before publishing.

PRESENTATION: ACCESS USER GROUPS (EUROPE)

Translate

PageRank

Post Feed


Search

Popular Posts

Blog Archive

Powered by Blogger.

Labels

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