Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Select statement help...getting "rows" back

Status
Not open for further replies.

Torn39

Technical User
Jul 25, 2002
14
US
Okay, this has got to be easy but I'm new to this so please help me out.

Have a nice form that's working great. I get two user numbers from this form that I multiply to get a number (X), now I need to use this number to bring back the first X rows from the query (base) created from the database...

SELECT ????? from qry.base where ??????.

For example, if x = 50 I want the first 50 rows from this query. I've gone through the Microsoft hel(l)p looking for how to just select what is essentially a 'Top N', but I can't find it....

Thanks for your help,

Torn
 
Well, I just set up a test using a query against a table which looks like this:

SELECT * FROM tblClient. And this query is qryAllClients

Now this query gets all columns for all rows of tblClient, about 60K rows.

So, I then built a query which reads thusly.

SELECT top 2000 * FROM qryAllClients and I get the first 2000 rows. Voila. So what is your question since you seem to have already answered it, or, are you asking how to build this in code based on the input from your form.

Let us assume the form variable holding the total count is Named x. so, we can do the following.

Dim strsql as string.
Dim rs as recordset

Strsql = “SELECT TOP “ & me.x.value & “FROM qryallClients”

Set rs = currentdb.openrecordset (strsql,dbopendynaset)

If I am totally off base here, tell me what I am missing.
Robert Berman
Data Base consultant
Vulcan Software Services
thornmastr@yahoo.com
 
Robert,

Thanks for your help. I got just mentally locked up on something very easy, and I appreciate you taking the time to help me out.

Thanks again,

Andy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top