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

Restricting query to x records 1

Status
Not open for further replies.

blakey

MIS
Feb 2, 2001
5
AU
Hi
I need to extract a number of records from sales table. When I use the top predicate it is either by percentage or number in the sql(hard coded). I want the sql to ask the user for the number of records required and ask the user for the sort order.

Output would then be for x records in the desired order.

Thanks
 
Blakey,

I messed around with this one a bit & wasn't able to do it with a parameter query. True to the documentation (surprise!), you could only put query parameters into the "WHERE" or "HAVING" clauses.

So (unless a real expert has the answer) you should consider doing a string build up based upon selection criteria entered in a form. This may not be what you wanted tho.

If this is what you'd like to do & you need help doing it then please let me know some particulars & we'll begin.
 
Use a form with comboboxes to solicit the parameters. Use a VBA routine to put these values into variables and insert the variables into a SQL statement, e.g.,

Dim strVar as string

strVar = MyCbo

DoCmd.RunSQL "SELECT " & strVar _
& " FROM" etc.

This is a cryptic offering but it should be pretty straightforward.
 
Thanks for the response. I had sort of figured out that it could not be done directly in sql and would need some form of a routine.

When I work it out I will let you know.

Cheers

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top