Our summer bowling leagues does brackets. We’ve been determining the bowler order for the bracket “manually” by drawing a random playing card. I would like to have Access assign the order randomly instead. A bracket has 8 bowlers. We have 10 brackets a night.
I’m very new to coding VBA but I’ve searched and arrived at this code. While it will give me a random number between 1 & 8 for each record, it will assign a number multiple times for new records.
Here is my code:
Private Sub BracketNo_Exit(Cancel As Integer)
' Generate random value between 1 and 8.
Dim RndSlot As Integer
Randomize
RndSlot = Int((8 - 1 + 1) * Rnd + 1)
If Me.BracketNo = 1 And Me.Week = Date Then
Me.BracketSlot = RndSlot
End If
End Sub
This produces:
Bowler Week Bracket BracketSlot
Robecca 4/13/2017 1 5
David 4/13/2017 1 7
Steve 4/13/2017 1 2
Nancy 4/13/2017 1 5
Toni 4/13/2017 1 8
Don 4/13/2017 1 7
Lola 4/13/2017 1 3
Bob 4/13/2017 1 5
5 & 7 are used multiple times, but 1, 4 & 6 aren't used. I'm sure it is because it's doesn't take in account the previous records entered.
What I need is more like shuffling 8 numbers into a random order and then in the new random order each number fills in the to the BracketSlot field as the bowler is entered.
I am stumped even at how to search.
I’m very new to coding VBA but I’ve searched and arrived at this code. While it will give me a random number between 1 & 8 for each record, it will assign a number multiple times for new records.
Here is my code:
Private Sub BracketNo_Exit(Cancel As Integer)
' Generate random value between 1 and 8.
Dim RndSlot As Integer
Randomize
RndSlot = Int((8 - 1 + 1) * Rnd + 1)
If Me.BracketNo = 1 And Me.Week = Date Then
Me.BracketSlot = RndSlot
End If
End Sub
This produces:
Bowler Week Bracket BracketSlot
Robecca 4/13/2017 1 5
David 4/13/2017 1 7
Steve 4/13/2017 1 2
Nancy 4/13/2017 1 5
Toni 4/13/2017 1 8
Don 4/13/2017 1 7
Lola 4/13/2017 1 3
Bob 4/13/2017 1 5
5 & 7 are used multiple times, but 1, 4 & 6 aren't used. I'm sure it is because it's doesn't take in account the previous records entered.
What I need is more like shuffling 8 numbers into a random order and then in the new random order each number fills in the to the BracketSlot field as the bowler is entered.
I am stumped even at how to search.