ACC2000: Difference Between MaxRecords and TopValues Properties (207621)



The information in this article applies to:

  • Microsoft Access 2000

This article was previously published under Q207621
Advanced: Requires expert coding, interoperability, and multiuser skills.

SUMMARY

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.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.

  3. Create a new query based on the linked table and include all fields.
  4. On the View menu, click Properties.
  5. Type 5 in the MaxRecords property.
  6. 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. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers 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 requirements.
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.

NOTE: The sample code in this article uses Microsoft Data Access Objects. For this code to run properly, you must reference the Microsoft DAO 3.6 Object Library. To do so, click References on the Tools menu in the Visual Basic Editor, and make sure that the Microsoft DAO 3.6 Object Library check box is selected.



Note In the following sample code, you must change UID=<username> and PWD=<strong password> to the correct values. Make sure that the user ID has the appropriate permissions to perform this operation on the database.
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=<username>;PWD=<strong password>;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
				

Modification Type:MinorLast Reviewed:10/11/2006
Keywords:kbDatabase kbhowto kbProgramming KB207621