This article was previously published under Q207621
Advanced: Requires expert coding, interoperability, and multiuser
skills.
Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.
View products that this article applies to.
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. |
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. |
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
Keywords: KB207621, kbprogramming, kbhowto, kbdatabase