Public Function GenerateRopingOrder(ByVal EventID As Long, ByVal MinSpacing As Long) As Boolean
On Error GoTo Err_GenerateRopingOrder
Dim UserResponse As Long
Dim conn As ADODB.Connection
Dim rstRegistration As ADODB.Recordset
Dim rstRopingOrder As New ADODB.Recordset
Dim SlotCount As Long
Dim MaxSlot As Long
Dim Spacing As Long
Dim i As Integer
Set conn = CurrentProject.Connection
Set rstRegistration = New ADODB.Recordset
UserResponse = MsgBox("Do you wish to reset the entire roping order?" & String(2, vbCrLf) & _
"Press 'Yes' to reset the entire roping order." & vbCrLf & _
"Press 'No' to create an order only for teams that have not yet been added to the roping order." & vbCrLf & _
"Press 'Cancel' to cancel this process.", vbQuestion + vbYesNoCancel, AppName)
If Not UserResponse = vbCancel Then
DoCmd.SetWarnings False
If UserResponse = vbYes Then
DoCmd.RunSQL "UPDATE tblRegistration SET RopingOrder = 0 WHERE EventID = " & EventID
End If
DoCmd.RunSQL "DELETE * FROM tblRopingOrder"
' DoCmd.RunSQL "DELETE * FROM tblRegistrationRandom"
' DoCmd.RunSQL "INSERT INTO tblRegistrationRandom (RegistrationID) SELECT RegistrationID FROM tblRegistration WHERE EventID = " & EventID
DoCmd.SetWarnings True
' rstRegistration.Open "SELECT tblRegistration.* FROM tblRegistration INNER JOIN tblRegistrationRandom ON tblRegistration.RegistrationID = tblRegistrationRandom.RegistrationID WHERE EventID = " & EventID & " AND RopingOrder = 0 ORDER BY Draw DESC, tblRegistrationRandom.Random", conn, adOpenStatic, adLockReadOnly
rstRegistration.Open "SELECT tblRegistration.* FROM tblRegistration WHERE EventID = " & EventID & " AND RopingOrder = 0 ORDER BY RegistrationID DESC", conn, adOpenStatic, adLockReadOnly
rstRopingOrder.Open "tblRopingOrder", conn, adOpenDynamic, adLockOptimistic, adCmdTable
MaxSlot = DMax("RopingOrder", "tblRegistration", "EventID = " & EventID)
SlotCount = DCount("RegistrationID", "tblRegistration", "EventID = " & EventID & " AND RopingOrder = 0"
If MinSpacing >= SlotCount * 0.05 Then
Spacing = SlotCount * 0.05 + 1
Else
Spacing = MinSpacing
End If
i = MaxSlot + 1
Do While Not rstRegistration.EOF
rstRopingOrder.AddNew
rstRopingOrder![RegistrationID] = rstRegistration![RegistrationID]
rstRopingOrder![Header] = rstRegistration![Header]
rstRopingOrder![Heeler] = rstRegistration![Heeler]
rstRopingOrder![Slot] = i
rstRopingOrder.Update
rstRegistration.MoveNext
i = i + 1
Loop
All this does, is take the first team and makes them the last team, when I need space between the same Header or the same heeler.