Pulling Select Random Records in Access Query

J

JLopez

I am working on pulling a random number or records in an
Access query (Top 3 for now) and am trying to figure out
how I can include every record from a related table at the
same time. I am currently using a randomizer function to
pull up 5 random records from one of my tables, the sql
for the query reads

SELECT TOP 3 tblOrders.*
FROM tblOrders
WHERE (((randomizer())=0))
ORDER BY Rnd(IsNull(tblOrders.OrderDescription)*0+1);


The function reads:
Function Randomizer() As Integer
Static AlreadyDone As Integer
If AlreadyDone = False Then Randomize: AlreadyDone = True
Randomizer = 0
End Function

I have a customer table (tblCustomers) whose recordset
looks like this:
-----------------------------------------------------------
| CustomerID | FirstName | LastName |
-----------------------------------------------------------
| 1 | John | Atkins |
-----------------------------------------------------------
| 2 | Beverly | McKinnon |
-----------------------------------------------------------
| 3 | Stewart | Larsen |
-----------------------------------------------------------
| 4 | Debra | Svenson |
-----------------------------------------------------------
| 5 | Angela | Mayor |
-----------------------------------------------------------
| 6 | Lewis | Hernandez |

The related Order table (tblOrders) looks like this:

---------------------------------------------------
| OrderID | CustomerID | OrderDescription |
---------------------------------------------------
| 5 | 1 | Notebook pad |
---------------------------------------------------
| 6 | 1 | Headset |
---------------------------------------------------
| 22 | 1 | Markers |
---------------------------------------------------
| 23 | 1 | Liquid paper |
---------------------------------------------------
| 11 | 2 | Lazerjet cartridge-Blue |
---------------------------------------------------
| 19 | 2 | Lazerjet cartridge-Black |
---------------------------------------------------
| 24 | 2 | Stamps |
---------------------------------------------------
| 25 | 2 | Envelopes |
---------------------------------------------------
| 16 | 3 | Notebook pad |
---------------------------------------------------
| 17 | 3 | Stationary |
---------------------------------------------------
| 18 | 3 | Headset |
---------------------------------------------------
| 20 | 3 | Markers |
---------------------------------------------------
| 21 | 3 | Ballpoint Pens |
---------------------------------------------------
| 7 | 4 | 3 Ring Binder |
---------------------------------------------------
| 10 | 4 | Legal Paper |
---------------------------------------------------
| 12 | 4 | Folders |
---------------------------------------------------
| 13 | 4 | 3 Ring Binder |
---------------------------------------------------
| 8 | 5 | Liquid paper |
---------------------------------------------------
| 9 | 5 | Stationary |
---------------------------------------------------
| 14 | 5 | Lazerjet cartridge-Black |
---------------------------------------------------
| 15 | 5 | Ballpoint Pens |
---------------------------------------------------
| 1 | 6 | Stationary |
---------------------------------------------------
| 2 | 6 | Ballpoint Pens |
---------------------------------------------------
| 3 | 6 | Legal Paper |
---------------------------------------------------
| 4 | 6 | Lazerjet cartridge-Black |
---------------------------------------------------


What I'm hoping to accomplish is a way to include all
employees, but just keep the orders randomized in
increments of 3.

Please let me know if you can find anything out.
 

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