By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,225 Members | 1,434 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,225 IT Pros & Developers. It's quick & easy.

TOP Records in SQL Statement

P: n/a
I've played with this for several hours trying to make it work with no
success. How do I replace "TOP 4" in the following SQL statement with
the input from a textbox on a form?
If possible I want to do this in the query itself - not an SQL
statement in code.

SELECT TOP 4 [SurName], [FirstName], [Company]
FROM RandCont
ORDER BY Rnd([Num]);

I need "TOP 4" to be replaced with something like
"Forms!MyForm!MyTextBox" so that I can specify how many records I want
in the textbox.

Any help would be appreciated.
Nov 13 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
It doesn't appear that it will accept a parameter for this value. Since you
are doing this on a form, you could rewrite the SQL of the query.

CurrentDb.QueryDefs("MyQuery").SQL = "SELECT TOP " & Me.txtMyTextbox &
"[SurName], [FirstName], [Company] FROM RandCont ORDER BY Rnd([Num]);"

--
Wayne Morgan
MS Access MVP
"Wayne Aprato" <cq*******@volcanomail.com> wrote in message
news:4d**************************@posting.google.c om...
I've played with this for several hours trying to make it work with no
success. How do I replace "TOP 4" in the following SQL statement with
the input from a textbox on a form?
If possible I want to do this in the query itself - not an SQL
statement in code.

SELECT TOP 4 [SurName], [FirstName], [Company]
FROM RandCont
ORDER BY Rnd([Num]);

I need "TOP 4" to be replaced with something like
"Forms!MyForm!MyTextBox" so that I can specify how many records I want
in the textbox.

Any help would be appreciated.

Nov 13 '05 #2

P: n/a
Thanks for the help Wayne.

"Wayne Morgan" <co***************************@hotmail.com> wrote in message news:<qC***************@newssvr24.news.prodigy.com >...
It doesn't appear that it will accept a parameter for this value. Since you
are doing this on a form, you could rewrite the SQL of the query.

CurrentDb.QueryDefs("MyQuery").SQL = "SELECT TOP " & Me.txtMyTextbox &
"[SurName], [FirstName], [Company] FROM RandCont ORDER BY Rnd([Num]);"

--
Wayne Morgan
MS Access MVP
"Wayne Aprato" <cq*******@volcanomail.com> wrote in message
news:4d**************************@posting.google.c om...
I've played with this for several hours trying to make it work with no
success. How do I replace "TOP 4" in the following SQL statement with
the input from a textbox on a form?
If possible I want to do this in the query itself - not an SQL
statement in code.

SELECT TOP 4 [SurName], [FirstName], [Company]
FROM RandCont
ORDER BY Rnd([Num]);

I need "TOP 4" to be replaced with something like
"Forms!MyForm!MyTextBox" so that I can specify how many records I want
in the textbox.

Any help would be appreciated.

Nov 13 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.