then it wouldn't be random would it. I thought by ensuring each team received one pick in each round until it exhausted it's pick was making it fair. I had originally used just a random process that sometimes ended up with the team with the lowest number of picks not getting a pick until the near the end of the process.
I added coding to check which position the team has piced from and if they've already picked from this position in a previous round, then to pick another team. Of course this doesn't ensure that the team with the fewest picks get high picks, it only ensures that the same team doesn't get to pick in the same position more than once until after the team with the fewest picks is finished.
Here is the new code (I decided to provide you with the new code instead of just the changes)
Function fDraftByRoundVer2()
Dim db As DAO.Database, rstTeams As DAO.Recordset, rstDraft As DAO.Recordset
Dim intX As Integer, intSelected As Integer, intDraws As Integer, intMinDraws
Dim intC As Integer, intRand As Integer, intRound As Integer, intRoundPicks
Dim strF As String
Set db = CurrentDb
With DoCmd
.SetWarnings False
.RunSQL ("Delete * from tbl_Draft_By_Rounds")
.RunSQL ("UPDATE tbl_Teams SET tbl_Teams.Drawn = Null")
.SetWarnings True
End With
intDraws = DMax("Entries", "tbl_Teams")
intMinDraws = DMin("Entries", "tbl_Teams")
intRand = Int(100 * Rnd())
Set rstTeams = db.OpenRecordset("tbl_Teams", dbOpenDynaset)
Set rstDraft = db.OpenRecordset("tbl_Draft_By_Rounds")
With rstDraft
For intC = 1 To intDraws
.AddNew
!DraftRound = intC
.Update
Next intC
End With
intC = 0
intRound = 1
Do While intRound < intDraws + 1
intRoundPicks = DCount("TeamNum", "tbl_Teams", "Entries >= " & intRound)
intSelected = 1
Do While intSelected < intRoundPicks + 1
intX = Right(intRand + Int(100 * Rnd()), 1)
'Debug.Print intX
With rstTeams
If intRound < intMinDraws + 1 Then
With rstDraft
.MoveFirst
Do While Not .EOF
If rstDraft("Position" & intSelected) = intX Then GoTo LoopHere
.MoveNext
Loop
End With
End If
.MoveFirst
.FindFirst "TeamNum= " & intX
If Not .NoMatch Then
If Nz(rstTeams!Drawn, 0) < rstTeams!Entries Then
With rstDraft
.Index = "PrimaryKey"
.Seek "=", intRound
If .NoMatch Then GoTo LoopHere
For intC = 1 To 20
If rstDraft("Position" & CStr(intC)) = intX Then GoTo LoopHere
Next intC
rstDraft.Edit
rstDraft("Position" & intSelected) = intX
rstDraft.Update
End With
rstTeams.Edit
rstTeams!Drawn = Nz(rstTeams!Drawn, 0) + 1
rstTeams.Update
intSelected = intSelected + 1
End If
End If
End With
LoopHere:
Loop
intC = 0
intSelected = 0
intRound = intRound + 1
Loop
Set rstDraft = Nothing
Set rstTeams = Nothing
Set db = Nothing
MsgBox "Completed determining draft order"
End Function
PaulF