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
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