ACC: How to Flag Out-of-Sequence Numbers on a Report

Last reviewed: August 28, 1997
Article ID: Q137118
The information in this article applies to:
  • Microsoft Access 7.0, 97

SUMMARY

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

This article shows you how to create a report that marks (or flags) any items that are missing from a given a list of sequential integers or dates. For example, when you receive your bank statement, your bank has flagged checks that have not cleared by placing an asterisk by the next check in the sequence. This article uses a Visual Basic for Applications function to compare the current item with the previous one in the sequence.

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.

MORE INFORMATION

To create a function that compares the current item with the previous one in a sequence, follow these steps.

CAUTION: Following the steps in this example will modify the sample database Northwind.mdb. You may want to back up the Northwind.mdb file and perform these steps on a copy of the database.

  1. Open the sample database Northwind.mdb.

  2. Create a new report based on the Current Product List query.

  3. On the View menu, click Code.

  4. Type the following code in the module's Declarations section:

    Dim GlobalFlag as Variant

  5. On the Insert menu, click Procedure. Type "SetFlag" (without the quotation marks) in the Name box, and then click OK.

  6. Modify the SetFlag function as follows:

    Function SetFlag(x as Variant)

              If GlobalFlag <> x - 1 then
                 SetFlag = "*"
              Else
                 SetFlag = ""
              End If
    
              GlobalFlag = x
           End Function
    
    

  7. Close the Code window.

  8. On the View menu, click Sorting and Grouping to display the Sorting and Grouping dialog box.

  9. In the first row of the Sorting and Grouping dialog box, select ProductID for the Field/Expression column and select Ascending for the Sort Order column.

  10. Close the dialog box.

  11. Add the following three text box controls to the detail section of the report:

    Textbox:

              Name: Product ID
              ControlSource: ProductID
           Textbox:
              Name: OutOfSequence
              ControlSource: =SetFlag([ProductID])
           Textbox:
              Name: Product Name
              ControlSource: ProductName
    
    

  12. Place the controls so that they are aligned horizontally and that the OutOfSequence control is flush against the Product ID control.

  13. To view the results, click Print Preview on the File menu. In the Preview window, note that an asterisk is placed next to each ProductID where the preceding ProductID is not in sequence.
Keywords          : kbusage PgmHowTo RptOthr
Version           : 7.0 97
Platform          : WINDOWS
Hardware          : x86
Issue type        : kbhowto


================================================================================


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: August 28, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.