Help with getting data from a table

G

Guest

I have a table with 7 records. There is a field [value] in the table. Each
record has a number in the value field.

In a form, I have 5 text boxes labeled value1, value2, value3, value4,
value5. I need to set: value1 = the highest number in the 7 records in the
[value] field
value2 = the 2nd highest number in the 7 records in the [value]
field
value3 = the 3rd highest number in the 7 records in the [value]
field
value4 = the 4th highest number in the 7 records in the [value]
field
value5 = the 5th highest number in the 7 records in the [value]
field.

Does anyone have an idea of how I can do this? Any help would be appreciated
Thanks
Please send response to: (e-mail address removed)
 
P

Pat Hartman\(MVP\)

If you use a subform or a listbox, there is a no code solution. Just create
a query with a TOP 5 predicate and order descending.

Select TOP 5 YourField
From YourTable
Order By YourField Desc;

Use the query as the RecordSource for a subform or the RowSource for a list
or combobox.
 
G

Guest

Hi Pat

I tried this. The results were the first 5 records, not the 5 records with
the highest numbers. I need to return the records for the 5 highest test
scores for each of 10 tests that are listed in the table. Column 1 of the
table is titled [Test Number]( through 10). Column 2 of the table is titled
[Grades](0-100).

Any other suggestions?


Pat Hartman(MVP) said:
If you use a subform or a listbox, there is a no code solution. Just create
a query with a TOP 5 predicate and order descending.

Select TOP 5 YourField
From YourTable
Order By YourField Desc;

Use the query as the RecordSource for a subform or the RowSource for a list
or combobox.

magicdds said:
I have a table with 7 records. There is a field [value] in the table. Each
record has a number in the value field.

In a form, I have 5 text boxes labeled value1, value2, value3, value4,
value5. I need to set: value1 = the highest number in the 7 records in
the
[value] field
value2 = the 2nd highest number in the 7 records in the [value]
field
value3 = the 3rd highest number in the 7 records in the [value]
field
value4 = the 4th highest number in the 7 records in the [value]
field
value5 = the 5th highest number in the 7 records in the [value]
field.

Does anyone have an idea of how I can do this? Any help would be
appreciated
Thanks
Please send response to: (e-mail address removed)
 
P

Pat Hartman\(MVP\)

Take a look at this kb article -
http://support.microsoft.com/default.aspx/kb/q208822/ It shows how to solve
the problem with a report. You may be able to adapt the technique.

magicdds said:
Hi Pat

I tried this. The results were the first 5 records, not the 5 records with
the highest numbers. I need to return the records for the 5 highest test
scores for each of 10 tests that are listed in the table. Column 1 of the
table is titled [Test Number]( through 10). Column 2 of the table is
titled
[Grades](0-100).

Any other suggestions?


Pat Hartman(MVP) said:
If you use a subform or a listbox, there is a no code solution. Just
create
a query with a TOP 5 predicate and order descending.

Select TOP 5 YourField
From YourTable
Order By YourField Desc;

Use the query as the RecordSource for a subform or the RowSource for a
list
or combobox.

magicdds said:
I have a table with 7 records. There is a field [value] in the table.
Each
record has a number in the value field.

In a form, I have 5 text boxes labeled value1, value2, value3, value4,
value5. I need to set: value1 = the highest number in the 7 records in
the
[value] field
value2 = the 2nd highest number in the 7 records in the
[value]
field
value3 = the 3rd highest number in the 7 records in the
[value]
field
value4 = the 4th highest number in the 7 records in the
[value]
field
value5 = the 5th highest number in the 7 records in the
[value]
field.

Does anyone have an idea of how I can do this? Any help would be
appreciated
Thanks
Please send response to: (e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top