Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I have tried this code and find that each time I open the program it starts down the same line (Item A is always first then item 5, etc.)
Could anyon help me put it so that I never know who comes next fully random?
Function FindRandom(Random As String, Field As String)Dim MyDB As Database
Dim MyRS As Recordset
Dim SpecificRecord As Long, i As Long, NumOfRecords As LongSet MyDB = CurrentDb()
Set MyRS = MyDB.OpenRecordset(Random, dbOpenDynaset)
MyRS.MoveLast
NumOfRecords = MyRS.RecordCount
SpecificRecord = Int(NumOfRecords * Rnd)
If SpecificRecord = NumOfRecords Then
SpecificRecord = SpecificRecord - 10
End If
MyRS.MoveFirst
For i = 1 To SpecificRecord
MyRS.MoveNext
Next i
FindRandom = MyRS(ID)
Exit FunctionNo Records:
If Err = 3021 Then
MsgBox "There Are No Records In The Dynset", 16, "Error"
Else
MsgBox "Error - " & Err & Chr$(13) & Chr(10) & Error, _
16, "Error"
End If
FindRandom = "No Records"
Exit FunctionEnd Function
James

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |