473,385 Members | 1,324 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

TOP Records in SQL Statement

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
2 1355
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Sans Spam | last post by:
Greetings! I have a table that contains all of the function permissions within a given application. These functions are different sections of a site and each has its own permissions (READ, WRITE,...
20
by: Guru | last post by:
Hi I have a table which contains number of rows. I want to fetch the last 5 records from the table. I know for the first 'n' records we can use FETCH FIRST n ROWS ONLY command. But i want to...
3
by: Peter Phelps | last post by:
My problem is as follows: I need automatically iterate through a single field in a table and use the values in the field to create an in-statement. Currently, the character limitation in the...
5
by: Terri | last post by:
I have a form with a multi-select combo. I dynamically build a SELECT statement, open a report, and set the recordsource to my dynamic SELECT statement. I count the records returned in the report...
3
by: celineusa | last post by:
Hello! Here is part of my database: tblStudents: StudentID tblMajorsAndStudents: StudentID, MajorID tblMajors: MajorID tblMajorsAndClasses: MajorID, ClassID, QuarterTaken tblClasses:...
4
by: John Herndon | last post by:
I have a VB.Net application that reads from a SQL database (SQL Server 7.0). How do I get the top 50% or bottom 50% of records from a certain table for my dataset? I keep getting an exception...
2
by: kevinjbowman | last post by:
I am by no means a SQl Jedi as will be apparent by my question, but I can usually figure out a select statement on my own. I have one today though that really has me stumped. I am working in...
0
by: padhuwork | last post by:
Hi, I want to create a Windows DLL using VC++ 6.0 which connects to SQL Server. After establishing the connection, I want to retrieve records from table (query) and out put the recordset to a...
14
by: dancer | last post by:
Using ASP.net 1.1 2 QUESTIONS: 1. Why do my write commands not work? 2. This file successfully makes changes in the database record. There surely is some simple code I could add that would...
2
maxamis4
by: maxamis4 | last post by:
Hello folks, I am still moving into the world of sql server and I need some help. In oracle there is a statement that is called "in list". Basically means what ever is returned from a select...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.