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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using TOP in SQL 1

Status
Not open for further replies.

Knicks

Technical User
Apr 1, 2002
383
US
I have a query that uses the TOP statement in a querie's SQL. Is there anyway I can have the user answer a prompt to fill in the number that normally appears right after the TOP statement.
 
I recently overcame a similar issue by modifying the sql string property of the querydef in code - something like this...

Dim strSQL As String
Dim intRecords As Integer

intRecords = InputBox("How Many Records Do You Want?", "Answer The Question")
strSQL = "SELECT TOP " & intRecords & " fieldname, fieldname FROM tblname WHERE blahblahblah"
db.QueryDefs("queryname").SQL = strSQL

Good Luck,
Poop
 
This looks really good. I currently just have an SQL statement saved as a query with the one twist being that it calls a procedure called Randomizer()in the criteria. As the reason for the statement is to get say 15 random records for auditing medical records. They change the random total every year using a percentage of total records.

Thanx
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top