ACC2000: Difference Between MaxRecords and TopValues Properties

ID: Q207621


The information in this article applies to:
  • Microsoft Access 2000


SUMMARY

Advanced: Requires expert coding, interoperability, and multiuser skills.

This article describes the differences between the MaxRecords property and the TopValues property.


MORE INFORMATION

The MaxRecords property sets or returns the maximum number of records of a query on an ODBC table and is useful in situations where limited client-resources prohibit management of large numbers of records from ODBC tables. The TopValues property is useful when you want to return certain records based on a specified percentage. MaxRecords is only for views in an Access project or queries in an ODBC data sources, not for queries on tables contained in the database, and is also available in Visual Basic.

The TopValues property returns a specified number of records or a percentage of records that meet the criteria you specify in the design of a query on any table. TopValues is not available in Visual Basic but can be used in tables contained in the database or ODBC tables. To set the number of records, TopValues requires a percent sign (%).

TopValues can return a number or a percent, whereas MaxRecords sets or returns only a number of records.

Examples of Using the MaxRecords and TopValues Properties

Using the MaxRecords Property

  1. Open the sample database Northwind.mdb.


  2. Link a table from a SQL Server.


  3. For more information about linking to SQL Server tables, click Microsoft Access Help on the Help menu, type Link data from ODBC data sources in the Office Assistant or the Answer Wizard, and then click Search to view the topic.

  4. Create a new query based on the linked table and include all fields.


  5. On the View menu, click Properties.


  6. Type 5 in the MaxRecords property.


  7. Run the query.

    Note that the query returns five records and that the records are in the order specified by the query's ORDER BY clause.


Using the TopValues Property

  1. Open the sample database Northwind.mdb.


  2. Open the Quarterly Orders query in Design view.


  3. On the View menu, click Properties, and set the TopValues property to 5%.


  4. Run the query.

    Note that the query returns 5% of the record count rounded up--that is, a table containing 20 records will return 1 record and a table containing 21 records will contain 2 records.


Example of Using MaxRecords in Visual Basic for Applications

Microsoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs. If you have limited programming experience, you may want to contact a Microsoft Certified Solution Provider or the Microsoft fee-based consulting line at (800) 936-5200. For more information about Microsoft Certified Solution Providers, please see the following page on the World Wide Web:

http://www.microsoft.com/mcsp/
For more information about the support options available from Microsoft, please see the following page on the World Wide Web:

http://www.microsoft.com/support/supportnet/overview/overview.asp

The following sample code is from Access Help. To find the example, in the Visual Basic Editor, click Microsoft Visual Basic Help, on the Help menu, type maxrecords property in the Office Assistant or the Answer Wizard, and then click Search to view the topic. In the What you you like to do dialog box, click MaxRecords Property (DAO). On the DAO Reference page, click Example.

The sample code in this article uses Microsoft Data Access Objects. For this code to run properly, you need to reference the Microsoft DAO 3.6 Object Library.



Sub MaxRecordsX()

    Dim dbsCurrent As DAO.Database
    Dim qdfPassThrough As DAO.QueryDef
    Dim qdfLocal As DAO.QueryDef
    Dim rstTemp As DAO.Recordset

    ' Open a database from which QueryDef objects can be
    ' created.
    Set dbsCurrent = OpenDatabase("DB1.mdb")

    ' Create a pass-through query to retrieve data from
    ' a Microsoft SQL Server database.
    Set qdfPassThrough = _
        dbsCurrent.CreateQueryDef("")

    ' Set the properties of the new query, limiting the 
    ' number of returnable records to 20.
    qdfPassThrough.Connect = _
        "ODBC;DATABASE=pubs;UID=sa;PWD=;DSN=Publishers"
    qdfPassThrough.SQL = "SELECT * FROM titles"
    qdfPassThrough.ReturnsRecords = True
    qdfPassThrough.MaxRecords = 20

    Set rstTemp = qdfPassThrough.OpenRecordset()

    ' Display results of query.
    Debug.Print "Query results:"
    With rstTemp
        Do While Not .EOF
            Debug.Print , .Fields(0), .Fields(1)
            .MoveNext
        Loop
        .Close
    End With

    dbsCurrent.Close

End Sub 

Additional query words: top values max records inf

Keywords : kbdta QryProp kbDatabase kbODBC
Version : WINDOWS:2000
Platform : WINDOWS
Issue type : kbhowto


Last Reviewed: July 8, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.