I use a collection object, this way you wont get repeat randoms.
It takes the table, reads all the INDEX into the collection
randomly picks 1 record, then removes it from list so it cant be picked again
sets the Order# on the table
repeats until the list is complete.
Code:
'this code marks records then flags that many records to be used.
Public Sub RandomOrder()
Dim iTot As Long, iRec As Long
Dim iSample As Integer
Dim sTbl As String, sSql As String
Dim rst 'As Recordset
Dim i As Long
Dim iRnd As Long, lNdx As Long
Dim coll As New Collection
Dim sKey As String
DoCmd.SetWarnings False
sTbl = "[tNAMES]"
'clear the order#
sSql = "update " & sTbl & " set [OrderNum] = null"
DoCmd.RunSQL sSql
'===================================
'collect all keys to alter their order
'===================================
Set rst = CurrentDb.OpenRecordset("select [ClientID] from " & sTbl)
With rst
While Not .EOF
sKey = rst.Fields(0).value & ""
coll.Add sKey, sKey
.MoveNext
Wend
End With
Set rst = Nothing
'===================================
'pick key at random then set new order for it
'===================================
i = 0
While coll.Count > 0
i = i + 1
iRnd = Int(coll.Count * Rnd + 1)
'Debug.Print iRnd
sKey = coll(iRnd)
lNdx = CLng(sKey)
sSql = "update " & sTbl & " set [OrderNum] = " & i & " where [ClientID]= " & lNdx
DoCmd.RunSQL sSql
coll.Remove sKey
nextNum:
Wend
DoCmd.SetWarnings True
DoCmd.OpenTable sTbl
MsgBox "done"
Set coll = Nothing
Exit Sub
Resume nextNum
End Sub