Top N values using textbox

C

ChoonBoy

How do I use a textbox to decide on the top number of records in a query? Eg.
If I want Top 12, I will enter 12 into the textbox and so on.. Click a button
and the query will open with the Top 12 customers.

Below is my Select SQL statement. I want the Top 10 to be controlled by a
textbox.

SELECT TOP 10 qryTblOrders3.custcode, qryTblOrders3.CustName,
Sum(qryTblOrders3.Sales) AS Top10Sales
FROM qryTblOrders3
GROUP BY qryTblOrders3.custcode, qryTblOrders3.CustName
ORDER BY Sum(qryTblOrders3.Sales) DESC;

Any help appreciated. Thanks in advance
 
C

ChoonBoy

Thanks it works. initially I did not notice the spelling error in the variable.

tkelley via AccessMonster.com said:
I left out a line:

after:
Dim intTopValues as integer

intTopValues = me.txtTopValues
Will this work?

Dim strSQL as string
Dim intTopValues as integer

strSQL = "SELECT TOP " & intTopValue & " qryTblOrders3.custcode,
qryTblOrders3.CustName,
Sum(qryTblOrders3.Sales) AS Top10Sales
FROM qryTblOrders3
GROUP BY qryTblOrders3.custcode, qryTblOrders3.CustName
ORDER BY Sum(qryTblOrders3.Sales) DESC;"

me.recordsource=strSQL
or
me.listbox.recordsource=strSQL
or
whatever it is you are wanting to fill with this recordsource.
How do I use a textbox to decide on the top number of records in a query? Eg.
If I want Top 12, I will enter 12 into the textbox and so on.. Click a button
[quoted text clipped - 10 lines]
Any help appreciated. Thanks in advance
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

I'm not sure how to return the value using the SQL statement? 4
Top 3 per group 3
Timeout issue 1
Enter Parametr Value 9
SQL with IIF 5
Union question... 2
Text box value as parameter in a query 4
DSUM in Form 4

Top