I'm trying to figure out some code to select random records out of a temp table that is created from code. Below is my attempt to create a table using the fields that I need, then I create a new field to populate the random number in the table. Then I want to take 50% of the total table and append to another database so those records can be analyzed. Can anyone be of assistance. The code below works until I get to the Do...Loop part. I'm not familiar with using the Do...Loop and feel I am missing something considering it wont stop running when I execute the code. Then I still have to get the 50% part added to it as well. Any assistance would be greatly appreciated. BTW I'm using Access 2000 on an NT machine if that helps any..
Sub RandNum()
Dim db As Database
Dim tdf As TableDef
Dim fld As Field
Dim rst As DAO.Recordset
Dim strSQL As String
Dim strTableName As String
strSQL = "SELECT table1.*, table2.NAME INTO tblTemp FROM table2 INNER JOIN table1 ON table2.NAME=table1.id WHERE (((table2.NAME)=[Forms]![Form1]![CmbX].[value]));"
DoCmd.SetWarnings False
DoCmd.RunSQL strSQL
DoCmd.SetWarnings True
Set db = CurrentDb()
Set tdf = db.TableDefs("tblTemp"
With tdf
.Fields.Append .CreateField("RandNumb", dbLong)
End With
Set rst = db.OpenRecordset("tblTemp"
Do
rst.MoveFirst
rst.Edit
Randomize
rst![RandNumb] = Rnd()
rst.Update
rst.MoveNext
Loop Until rst.EOF
rst.Close
Set rst = Nothing
End Sub
Sub RandNum()
Dim db As Database
Dim tdf As TableDef
Dim fld As Field
Dim rst As DAO.Recordset
Dim strSQL As String
Dim strTableName As String
strSQL = "SELECT table1.*, table2.NAME INTO tblTemp FROM table2 INNER JOIN table1 ON table2.NAME=table1.id WHERE (((table2.NAME)=[Forms]![Form1]![CmbX].[value]));"
DoCmd.SetWarnings False
DoCmd.RunSQL strSQL
DoCmd.SetWarnings True
Set db = CurrentDb()
Set tdf = db.TableDefs("tblTemp"
With tdf
.Fields.Append .CreateField("RandNumb", dbLong)
End With
Set rst = db.OpenRecordset("tblTemp"
Do
rst.MoveFirst
rst.Edit
Randomize
rst![RandNumb] = Rnd()
rst.Update
rst.MoveNext
Loop Until rst.EOF
rst.Close
Set rst = Nothing
End Sub