Retrieving Random records from table or query

  • Thread starter Thread starter copels
  • Start date Start date
C

copels

Guest
Hi,

I have found Joe Foster's code for retrieving random records but when I try to use it in a module I get a syntax error in the WHERE line.

Please could somebody tell me what I am doing wrong as I am going mad!

Many thanks
STeve


The code is as follows:

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


Sub SelectIntoX()
Dim dbs As Database
Set dbs = CurrentDb


' Select top 6 records in the QueryTemplate
' and copy them into a new table called Query_to_print

dbs.Execute "SELECT top 6 QueryTemplate.* INTO" _
& "[Query_to_print] FROM QueryTemplate" _
& "WHERE Randomizer() = 0" _
& "ORDER BY rnd(isnull(QueryTemplate.*) * 0 + 1)"


End Sub
 
Hi
i think that it needs a space before the W of where and also before the O of order

Norman
 

Users who are viewing this thread

Back
Top Bottom