A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » General Discussion
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Random Sort



 
 
Thread Tools Display Modes
  #1  
Old March 24th, 2010, 03:38 PM posted to microsoft.public.access
Guy[_11_]
external usenet poster
 
Posts: 6
Default Random Sort

What funcrion can I use in a query to accomplish a random sort?

Guy


  #2  
Old March 24th, 2010, 05:05 PM posted to microsoft.public.access
Jerry Whittle
external usenet poster
 
Posts: 4,732
Default Random Sort

SELECT asa.*
FROM asa
WHERE (((randomizer())=0))
ORDER BY Rnd(IsNull([asa].[AsaID])*0+1);

Change asa to your table name.

For the AsaID field, use a number field. An autonumber field would be best.

--
Jerry Whittle, Microsoft Access MVP
Light. Strong. Cheap. Pick two. Keith Bontrager - Bicycle Builder.


"Guy" wrote:

What funcrion can I use in a query to accomplish a random sort?

Guy


.

  #3  
Old March 24th, 2010, 05:13 PM posted to microsoft.public.access
John W. Vinson
external usenet poster
 
Posts: 18,261
Default Random Sort

On Wed, 24 Mar 2010 10:38:52 -0500, "Guy" wrote:

What funcrion can I use in a query to accomplish a random sort?

Guy

You can use help from a little VBA. Put this little function into a Module:

Public Function RndNum(vIgnore As Variant) As Double
Static bRnd As Boolean
If Not bRnd Then
'Initialize the random number generator once only
bRnd = True
Randomize
End If
RndNum = Rnd()
End Function

Then add a calculated field to your Query by typing

Shuffle: RndNum([fieldname])

in a vacant Field cell, where [fieldname] is any field in
your table - this forces Access to give a different random
number for each record.

Sort the query by Shuffle.

--

John W. Vinson [MVP]
 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 02:34 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.