Not in a query, but you can do it in code. Suppose txtTopValue is the
textbox with the Top value. Save the recordset data in a temporary table
(air code):
Sub txtTopValue_AfterUpdate()
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim rst2 As DAO.Recordset
Dim n As Integer
Dim strSQL as string
Dim i As Integer
Set db = CurrentDb
n = Val(Me![txtTopValue].Text)
strSQL = "SELECT TOP " & n & " ID, Qty FROM Table1 ORDER BY Table1.Qty
DESC;"
Set rst = db.OpenRecordset(strSQL)
Set rst2 = db.OpenRecordset("tmpTable", dbOpenDynaset)
With rst
.MoveFirst
Do Until .EOF
rst2.AddNew
rst2!ID = !ID
rst2!Qty = !Qty
rst2.Update
.MoveNext
Loop
End With
Exit_Here:
'Close everything
End Sub
Now you can pull a query on the data in the temp table. If you plan on
doing this regularly, add code in the beginning to delete the contents of
the temp table.
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com
Bonnie said:
Thanks for responding Arvin. Is it possible to use input from a control
for
the top parameter? So it would be TOP forms!myform.control?
Thanks,
Bonnie