Re: Random Sampling
  Home FAQ Contact Sign in
microsoft.public.access only
Advanced search


Re: Random Sampling         

Group: microsoft.public.access · Group Profile
Author: Arvin Meyer [MVP]
Date: May 13, 2010 14:57

I'd do it with 3 queries, one for each type, then if necessary to combine
them, use a union query. So:

Create a function in a module:

Function GetRandNum(varValue As Variant) As Double
Randomize Timer
GetRandNum = Rnd(1)
End Function

The query would look like:

SELECT TOP 10 ID, [Name], [Date], Type
FROM YourTableName
WHERE Type = "A" ' or B or C
ORDER BY GetRandNum(ID);

Also, note that Name and Date are reserved words and you will have big
problems using them, which is why I used square brackets around them.

Now the Union query looks like:

Select * From Query A
Select * From Query B
Select * From Query C;
Arvin Meyer, MCP, MVP

"Paul"> wrote in message
> Hello. I have a table in Access that is updated each day with data
> from the previous business day. The table consists of a date, name,
> type and id. For this example, let's say that the types are Type A,
> Type B or Type C. I need to take a random sampling of 10 id's for
> each of the different Types for each Name that is listed for a
> particular day. For example if 1 agent worked yesterday, I would
> need to see a random sampling of 10 Type A id's, 10 Type B id's and 10
> Type C id's for a grand total of 30. If more agents worked then I
> would need to have the same for each of them.
> Does this make sense? 10 random id numbers of each type for each
> agent that worked on a particular day. Does anyone have any thoughts
> on this?
> Any help would be greatly appreciated.
> Thanks
no comments
diggit!! reddit!