Group:  Microsoft Access ยป microsoft.public.access.formscoding
Thread: Top N values using textbox

Geek News

Top N values using textbox
ChoonBoy 12/18/2008 5:00:01 PM
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
Re: Top N values using textbox
"tkelley via AccessMonster.com" <u47368[ at ]uwe> 12/18/2008 6:02:53 PM
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.

ChoonBoy wrote:
[Quoted Text]
>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

--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/Forums.aspx/access-formscoding/200812/1

Re: Top N values using textbox
"tkelley via AccessMonster.com" <u47368[ at ]uwe> 12/18/2008 6:03:44 PM
I left out a line:

after:
Dim intTopValues as integer

intTopValues = me.txtTopValues

tkelley wrote:
[Quoted Text]
>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

--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/Forums.aspx/access-formscoding/200812/1

Re: Top N values using textbox
ChoonBoy 12/19/2008 6:27:00 AM
Thanks it works. initially I did not notice the spelling error in the variable.

"tkelley via AccessMonster.com" wrote:

[Quoted Text]
> I left out a line:
>
> after:
> Dim intTopValues as integer
>
> intTopValues = me.txtTopValues
>
> tkelley wrote:
> >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
>
> --
> Message posted via AccessMonster.com
> http://www.accessmonster.com/Uwe/Forums.aspx/access-formscoding/200812/1
>
>

Home | Search | Terms | Imprint Contact
Newsgroups Reader - provided by WiredBox.Net