pbuethe
Returning User
- Local time
- Today, 05:58
- Joined
- Apr 9, 2002
- Messages
- 210
I am trying to mark a random set of records in the table. The user enters the percentage of records to mark (txtPercentage). e.g. if the user wants to mark 45% of the records (s)he would enter 45 on the form. There are other criteria for selecting records also. It seems to work except that it is not selecting enough records.
e.g. if trying to mark 45% of 37 records, it should mark 17 records, but it is only marking 14.
My code is as follows:
Before calling this sub I execute a query which clears the Contract field, and then call Randomize. Then the sub is called several times using different queries as stQuery.
Thanks as always for your help.
e.g. if trying to mark 45% of 37 records, it should mark 17 records, but it is only marking 14.
My code is as follows:
Code:
Sub MarkTitleI(stAUID As String, stSample As String, stRType As String, stLType As String, stQuery As String)
Dim R As Recordset
Dim Q As QueryDef
Dim Top, Bottom, K, Max
Set Q = dbs.QueryDefs(stQuery)
Q.Parameters("pAUID") = stAUID
Q.Parameters("pSample") = stSample
Q.Parameters("pRevType") = stRType
Q.Parameters("pListType") = stLType
Set R = Q.OpenRecordset()
R.MoveLast: R.MoveFirst 'set recordcount
Top = 0
Bottom = R.RecordCount - 1
Max = R.RecordCount
For K = 1 To Int(Max * 0.01 * Forms!frmTitleIEntry!txtPercentage)
R.MoveFirst
'move to a random record
R.Move Int((Top - Bottom + 1) * Rnd + Bottom)
R.Edit
R.Fields("Contract") = "Title I"
R.Update
R.Requery 'remove all non-zero records
Bottom = Bottom - 1 'adjust random range
Next K
R.Close
End Sub
Before calling this sub I execute a query which clears the Contract field, and then call Randomize. Then the sub is called several times using different queries as stQuery.
Thanks as always for your help.