This example uses the MaxRecords property to open a Recordset containing the 10 most expensive titles in the Titles table.
'BeginMaxRecordsVB 'To integrate this code 'replace the data source and initial catalog values 'in the connection string Public Sub MaxRecordsX() Dim rstTitles As ADODB.Recordset Dim Cnxn As ADODB.Connection Dim strCnxn As String Dim strSQLTitles As String ' Open a connection Set Cnxn = New ADODB.Connection strCnxn = "Provider=sqloledb;Data Source=MyServer;Initial Catalog=pubs;User Id=sa;Password=;" Cnxn.Open strCnxn ' Open recordset containing the 10 most expensive ' titles in the Titles table Set rstTitles = New ADODB.Recordset rstTitles.MaxRecords = 10 strSQLTitles = "SELECT Title, Price FROM Titles ORDER BY Price DESC" rstTitles.Open strSQLTitles, strCnxn, adOpenStatic, adLockReadOnly, adCmdText ' Display the contents of the recordset Debug.Print "Top Ten Titles by Price:" Do Until rstTitles.EOF Debug.Print " " & rstTitles!Title & " - " & rstTitles!Price rstTitles.MoveNext Loop ' clean up rstTitles.Close Cnxn.Close Set rstTitles = Nothing Set Cnxn = Nothing End Sub 'EndMaxRecordsVB
MaxRecords Property | Recordset Object
© 1998-2001 Microsoft Corporation. All rights reserved.