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

Query question 1

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I have a DB, one of its table contains 1000 question in diffirent
courses, i want want to make a query to select one course,
and then select five question from that query randomly.

i.e suppose the courses r math,physics,chem, each with 333 question
the query will bring just the math questions, and from it, i'll
select five questions randomly
 
Hi,

You will not be able to do this with simple SQL. I don't know if you can do this with the functions built into the Access query builder. You should build some kind of random number generator. This is simple in VB. You could then create a recordset with just Math records then randomly select a record number.

This can all be done in an Access Form. Using VBA.
 
To give you an idea of how this could be accomplished:

(1) Copy Function Randomizer, displayed at this link:

(2) Open Northwind.mdb, create a new module and paste the code from step 1.

(3) In Northwind, save query Alphabetical List of Products as QryTest. In QryTest design view, move CategoryName so that it's the first field in the grid and set CategoryName's sort to ascending.

(4) Open a new query and copy/paste this SQL:

SELECT TOP 3 QryTest.*
FROM QryTest
WHERE (((QryTest.CategoryName)="beverages") AND ((randomizer())=0))
ORDER BY Rnd(IsNull(qrytest.productname)*0+1);

(5) Save this query as QryTest2. Now you're ready to test it. Each time you open QryTest2, you'll be presented with three randomly selected records from Category "Beverages" (comparable to Math, Physics, etc.)

Hope this gives you a starting point.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top