Article ID: 183244
Article Last Modified on 1/22/2007
Sub MaxRecordsX()
Dim dbsCurrent As Database
Dim qdfPassThrough As QueryDef
Dim qdfLocal As QueryDef
Dim rstTemp As 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. You will need to replace
' <username> and <strong password> with the UID and PWD
' of an account that has the appropriate permissions.
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
Additional query words: top values max records
Keywords: kbinfo KB183244