ACC: How to Use the Status Bar Progress Meter

ID: Q103404

The information in this article applies to:

SUMMARY

Moderate: Requires basic macro, coding, and interoperability skills.

You can use the SysCmd() function in Microsoft Access to create a progress meter in the status bar that gives a visual representation of the progress of an operation. When you perform an operation with a known duration or number of steps, you can use the SysCmd() function to visually represent the operation's progress.

This article shows you how to use the SysCmd() function in Microsoft Access to display a progress meter.

This article assumes that you are familiar with Visual Basic for Applications and with creating Microsoft Access applications using the programming tools provided with Microsoft Access. For more information about Visual Basic for Applications, please refer to your version of the "Building Applications with Microsoft Access" manual.

NOTE: Visual Basic for Applications is called Access Basic in Microsoft Access versions 1.x and 2.0. For more information about Access Basic, please refer to the "Introduction to Programming" manual in Microsoft Access version 1.x or the "Building Applications" manual in Microsoft Access version 2.0.

MORE INFORMATION

The syntax of the SysCmd() function is

   SysCmd(<action> [, <text>][, <value>])

where

    - <action> is a numeric expression identifying the type of action
      to take. The expression is one of the following:

         1 - Initialize the progress meter.
         2 - Update the progress meter with the specified value.
         3 - Remove the progress meter.

    - <text> is a string expression identifying the text that will
      appear left-aligned in the status bar to the left of the
      progress meter.

    - <value> is a numeric expression that controls the display of the
      meter. This is required when the action is 1 or 2.

      When the action is 1, the value indicates the maximum number the
      meter should display, with the maximum value for the meter
      indicating 100 percent.

      When the action is 2, the value is used to calculate and update
      the percentage complete in the progress meter.

NOTE: The SysCmd() function returns NULL, which is not used.

Initializing the Progress Meter

When the <action> argument is 1, the <value> argument is the maximum value of the meter, or 100 percent. To display a progress meter with a maximum value of 1000 initialized, type the following line in the Debug window (or Immediate window in versions 1.x and 2.0):

   ? SysCmd(1, "This is my meter!", 1000)

Updating the Progress Meter

When the <action> argument is 2, the <value> argument is used by SysCmd() to calculate the percentage displayed by the meter. To update the progress meter to 25 percent complete, type the following line in the Debug window (or Immediate window in versions 1.x and 2.0):

   ? SysCmd(2, 250)

Removing the Progress Meter

When the <action> argument is 3, the progress meter is removed from the status bar. To remove the meter, type the following line in the Debug window (or Immediate window in versions 1.x and 2.0):

   ? SysCmd(3)

Using SysCmd() in a Visual Basic Function

The following sample function opens the Customers table in the sample database Northwind.mdb (or NWIND.MDB in versions 1.x or 2.0). The function displays a list of the contact names in the table. As the names display, a meter progresses in the status bar indicating the relative progress of the function.

1. Open the sample database Northwind.mdb (or NWIND.MDB in versions

   1.x and 2.0).

2. Create a new module called "Meter Test."

3. Type the following line in the Declarations section if it is not

   already there:

      Option Explicit

4. Type the following procedure:

      Function Meter ()
         Dim MyDB As Database, MyTable As RecordSet
         Dim Count As Long
         Dim Progress_Amount As Integer, RetVal As Variant

         Set MyDB = CurrentDB()
         Set MyTable = MyDB.OpenRecordSet("Customers")

         ' Move to last record of the table to get the total
         ' number of records.
         MyTable.MoveLast
         Count = MyTable.RecordCount

         ' Move back to first record.
         MyTable.MoveFirst

         ' Initialize the progress meter.
         RetVal = SysCmd(1, "Reading Data...", Count)

         ' Enumerate through all the records.
         For Progress_Amount = 1 To Count
           ' Update the progress meter.
           RetVal = SysCmd(2, Progress_Amount)

           'Print the contact name in the Debug window (or Immediate window
           'in versions 1.x and 2.0).

           Debug.Print MyTable![ContactName]

           ' NOTE: In versions 1.x and 2.0, there is a space in Contact
           ' Name.

           ' Goto the next record.
           MyTable.MoveNext
         Next Progress_Amount

         ' Remove the progress meter.
         RetVal = SysCmd(3)
      End Function

5. To run the function, type the following line in the Debug window (or
   Immediate window in versions 1.x and 2.0), and then press ENTER:

      ? Meter()

REFERENCES

For more information about the SysCmd() function, search the Help Index for "SysCmd."

Additional query words: thermometer statusbar

Keywords          : kbprg kbusage
Version           : 1.0 1.1 2.0 7.0 97
Platform          : WINDOWS
Hardware          : x86
Issue type        : kbhowto

Last Reviewed: November 20, 1998