Query?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a table with two fields (questions and
catagories). The catagories is a drop down list with four
choices. Is it possible to query 10 random questions from
each catagorie?
Thanks
Rick
 
Firstly random selection is achieved by passing your auto-number field into
the Rnd() function. Access does nothing with the numeric field, but if you
don't pass something in the query optimizer doesn't bother calling the
function for every row.

Queries have a Top Values property where you can ask for a specific number
of records:
SELECT TOP 10 * FROM MyTable ORDER BY Rnd([QuestionID]);
However, you need to run the query once for each category to get 10
questions per category.

A simple solution is to create a report that lists the categories, with a
subreport to list the questions in each category. Access matches the query
to the category, and pulls out a random selection of records until it has 10
from each category.

Don't forget to execute a Randomize.
 
What I really want is to have 10 questions from each
catagorie on one report, but mixed up on the report, not
seperated into catagories on the report. Is that possible
somehow?
Thanks Rick
-----Original Message-----
Firstly random selection is achieved by passing your auto-number field into
the Rnd() function. Access does nothing with the numeric field, but if you
don't pass something in the query optimizer doesn't bother calling the
function for every row.

Queries have a Top Values property where you can ask for a specific number
of records:
SELECT TOP 10 * FROM MyTable ORDER BY Rnd ([QuestionID]);
However, you need to run the query once for each category to get 10
questions per category.

A simple solution is to create a report that lists the categories, with a
subreport to list the questions in each category. Access matches the query
to the category, and pulls out a random selection of records until it has 10
from each category.

Don't forget to execute a Randomize.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

I have a table with two fields (questions and
catagories). The catagories is a drop down list with four
choices. Is it possible to query 10 random questions from
each catagorie?
Thanks
Rick


.
 
1. Create a table to hold just the primary key value of the questions.

2. Open a recordset into each category. Loop through the categories, and use
an Append query statement to select a TOP 10 random sort and write the p.k.
value to the temp table.

3. Base the report on a query that joins the temp table to the table of
questions.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

What I really want is to have 10 questions from each
catagorie on one report, but mixed up on the report, not
seperated into catagories on the report. Is that possible
somehow?
Thanks Rick
-----Original Message-----
Firstly random selection is achieved by passing your auto-number field into
the Rnd() function. Access does nothing with the numeric field, but if you
don't pass something in the query optimizer doesn't bother calling the
function for every row.

Queries have a Top Values property where you can ask for a specific number
of records:
SELECT TOP 10 * FROM MyTable ORDER BY Rnd ([QuestionID]);
However, you need to run the query once for each category to get 10
questions per category.

A simple solution is to create a report that lists the categories, with a
subreport to list the questions in each category. Access matches the query
to the category, and pulls out a random selection of records until it has 10
from each category.

Don't forget to execute a Randomize.


I have a table with two fields (questions and
catagories). The catagories is a drop down list with four
choices. Is it possible to query 10 random questions from
each catagorie?
Thanks
Rick
 
Okay, forgot to say I'm new at this. I understand how to
create a table and the last base a report on a query. Not
sure how to do the rest, any help?
Thank you very much,
Rick
-----Original Message-----
1. Create a table to hold just the primary key value of the questions.

2. Open a recordset into each category. Loop through the categories, and use
an Append query statement to select a TOP 10 random sort and write the p.k.
value to the temp table.

3. Base the report on a query that joins the temp table to the table of
questions.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

What I really want is to have 10 questions from each
catagorie on one report, but mixed up on the report, not
seperated into catagories on the report. Is that possible
somehow?
Thanks Rick
-----Original Message-----
Firstly random selection is achieved by passing your auto-number field into
the Rnd() function. Access does nothing with the
numeric
field, but if you
don't pass something in the query optimizer doesn't bother calling the
function for every row.

Queries have a Top Values property where you can ask
for
a specific number
of records:
SELECT TOP 10 * FROM MyTable ORDER BY Rnd ([QuestionID]);
However, you need to run the query once for each category to get 10
questions per category.

A simple solution is to create a report that lists the categories, with a
subreport to list the questions in each category.
Access
matches the query
to the category, and pulls out a random selection of records until it has 10
from each category.

Don't forget to execute a Randomize.


I have a table with two fields (questions and
catagories). The catagories is a drop down list with four
choices. Is it possible to query 10 random questions from
each catagorie?
Thanks
Rick


.
 
If you are able to write VBA code, you can open the recordset and do the
whole thing programmatically. If not, you will need to enter each category
manually.

1. Create a query into your table, using the query statement given
previously.

2.Change it to an Append query (Append on Query menu).
Access asks for the name of the table to append to: the temp table.

3. In the Criteria row under Category, enter the first category value.

4. Run the query to append the primary key to the temp table.

5. Repeat steps 3 and 4 for the other category values.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Okay, forgot to say I'm new at this. I understand how to
create a table and the last base a report on a query. Not
sure how to do the rest, any help?
Thank you very much,
Rick
-----Original Message-----
1. Create a table to hold just the primary key value of the questions.

2. Open a recordset into each category. Loop through the categories, and use
an Append query statement to select a TOP 10 random sort and write the p.k.
value to the temp table.

3. Base the report on a query that joins the temp table to the table of
questions.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

What I really want is to have 10 questions from each
catagorie on one report, but mixed up on the report, not
seperated into catagories on the report. Is that possible
somehow?
Thanks Rick
-----Original Message-----
Firstly random selection is achieved by passing your
auto-number field into
the Rnd() function. Access does nothing with the numeric
field, but if you
don't pass something in the query optimizer doesn't
bother calling the
function for every row.

Queries have a Top Values property where you can ask for
a specific number
of records:
SELECT TOP 10 * FROM MyTable ORDER BY Rnd
([QuestionID]);
However, you need to run the query once for each
category to get 10
questions per category.

A simple solution is to create a report that lists the
categories, with a
subreport to list the questions in each category. Access
matches the query
to the category, and pulls out a random selection of
records until it has 10
from each category.

Don't forget to execute a Randomize.
 
Allen,
Thank you, I will give it a try.
Rick
-----Original Message-----
If you are able to write VBA code, you can open the recordset and do the
whole thing programmatically. If not, you will need to enter each category
manually.

1. Create a query into your table, using the query statement given
previously.

2.Change it to an Append query (Append on Query menu).
Access asks for the name of the table to append to: the temp table.

3. In the Criteria row under Category, enter the first category value.

4. Run the query to append the primary key to the temp table.

5. Repeat steps 3 and 4 for the other category values.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Okay, forgot to say I'm new at this. I understand how to
create a table and the last base a report on a query. Not
sure how to do the rest, any help?
Thank you very much,
Rick
-----Original Message-----
1. Create a table to hold just the primary key value
of
the questions.
2. Open a recordset into each category. Loop through
the
categories, and use
an Append query statement to select a TOP 10 random
sort
and write the p.k.
value to the temp table.

3. Base the report on a query that joins the temp
table
to the table of
questions.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

What I really want is to have 10 questions from each
catagorie on one report, but mixed up on the report, not
seperated into catagories on the report. Is that possible
somehow?
Thanks Rick
-----Original Message-----
Firstly random selection is achieved by passing your
auto-number field into
the Rnd() function. Access does nothing with the numeric
field, but if you
don't pass something in the query optimizer doesn't
bother calling the
function for every row.

Queries have a Top Values property where you can
ask
for
a specific number
of records:
SELECT TOP 10 * FROM MyTable ORDER BY Rnd
([QuestionID]);
However, you need to run the query once for each
category to get 10
questions per category.

A simple solution is to create a report that lists the
categories, with a
subreport to list the questions in each category. Access
matches the query
to the category, and pulls out a random selection of
records until it has 10
from each category.

Don't forget to execute a Randomize.


.
 
Back
Top