Borrowing some of HansV’s code I created a function to populate a table with 50 random numbers from another tables autonumber field.
Problem: The code selects some of the recordID’s that have been deleted and I’m getting some duplicates in the new table that I’m populating with the 50 numbers.
How do I check for only the actual numbers in the autoNumber field and not just the count of them
Here is the function
Function Create50()
Dim intRandom As Integer
Dim intPreviousRandom As Integer
Dim CntRecord As Integer
Dim i As Integer
Dim db As Database
Dim rst, rst1 As Recordset
Set db = CurrentDb
Set rst = db.OpenRecordset(“qryResponders”) ‘query of the table that has the AutoNumber field
Set rst1 = db.OpenRecordset(“tblID”) ‘ table that I’m appending the random 50 numbers to
CntRecord = rst.RecordCount
i = 1
For i = 1 To 100 – 1
intPreviousRandom = intRandom
‘ Get random number until different from previous value
Do
intRandom = Int(Rnd * CntRecord + 1)
Loop Until intRandom intPreviousRandom
rst1.AddNew
rst1!ID = intRandom
rst1.Update
i = i + 1
Next
End Function