Restrict number of records returned by query on form

  • Thread starter Thread starter Robert
  • Start date Start date
R

Robert

I have a form with a list box on it. The list box displays the result of a
query. The Openargs which is input to the form contains a number. I want
to limit the list box to that number of records. That's all. It can
display any of the records as long as the number does not exceed this input
variable number. The rest of the records do not appear. What is the
simplest way of doing this? Should I try to put a SELECT TOP or something
like that in my query or should I add a numbering column and use the where
clause to select only those records <= the openargs.

Robert
 
Robert said:
I have a form with a list box on it. The list box displays the result of a
query. The Openargs which is input to the form contains a number. I want
to limit the list box to that number of records. That's all. It can
display any of the records as long as the number does not exceed this input
variable number. The rest of the records do not appear. What is the
simplest way of doing this? Should I try to put a SELECT TOP or something
like that in my query or should I add a numbering column and use the where
clause to select only those records <= the openargs.


A TOP query is more efficient, but to get the number of
records into the query, you will have to construct the query
in VBA code and assign it to the list box's RowSource
property.

Using a sequence numbered column is more complex and less
efficient, but the query can be precreated and the WHERE
clause can use a hidden text box on a form as a parameter
criteria.

Either way, the data must have a unique sort order to get a
specific number of records.
 
I was able to get the code to work. Thank you.
Marshall Barton said:
A TOP query is more efficient, but to get the number of
records into the query, you will have to construct the query
in VBA code and assign it to the list box's RowSource
property.

Using a sequence numbered column is more complex and less
efficient, but the query can be precreated and the WHERE
clause can use a hidden text box on a form as a parameter
criteria.

Either way, the data must have a unique sort order to get a
specific number of records.
 
Back
Top