Using the code:
Dim Check, Counter
Check = True: Counter = 0 ' Initialize variables.
Do ' Outer loop.
Do While Counter < 20 ' Inner loop.
Counter = Counter + 1 ' Increment Counter.
If Counter = 10 Then ' If condition is True.
Check = False ' Set value of flag to False.
Exit Do ' Exit inner loop.
End If
Loop
Loop Until Check = False ' Exit outer loop immediately
works great!
BUT
When I insert the rest of my code in between and execute it tells me there is a compile error: Loop without Do
This is what that code looks like:
Private Sub Check_Click()
Dim Check, Counter
Dim CountNum As Integer
Check = True: Counter = 0 ' Initialize variables.
Do
Do While Counter < 405
'Set Winning Amount to zero
Me!Winnings = 0
' Set label + Bonus to not visible
Me!AndBonus.Visible = False
' Set the counter to zero
CountNum = 0
' Set all winning fields to empty
Me!M1 = ""
Me!M2 = ""
Me!M3 = ""
Me!M4 = ""
Me!M5 = ""
Me!M6 = ""
Me!MB = ""
' Check That a valid date has been selected
If IsNull(Me!DrawDate) Then
MsgBox "Please select a valid date!", vbCritical, "Select a valid date!"
Exit Sub
End If
' Check all fields are filled in
If IsNull(CInt(Me!C1)) Or IsNull(CInt(Me!C2)) Or IsNull(CInt(Me!C3)) Or IsNull(CInt(Me!C4)) Or IsNull(CInt(Me!C5)) Or IsNull(CInt(Me!C6)) Then
MsgBox "All 6 fields must be filled in!", vbCritical, "Complete all numbers!"
Exit Sub
End If
' Check my Ball 1 to winning ball 1
If CInt(Me!C1) = Me!B1 Then
Me!M1 = Me!B1
CountNum = CountNum + 1
Else
Me!M1 = Me!M1
End If
' Check my Ball 2 to winning ball 1
If CInt(Me!C2) = Me!B1 Then
Me!M1 = Me!B1
CountNum = CountNum + 1
Else
Me!M1 = Me!M1
End If
' Check my Ball 3 to winning ball 1
If CInt(Me!C3) = Me!B1 Then
Me!M1 = Me!B1
CountNum = CountNum + 1
Else
Me!M1 = Me!M1
End If
' Check my Ball 4 to winning ball 1
If CInt(Me!C4) = Me!B1 Then
Me!M1 = Me!B1
CountNum = CountNum + 1
Else
Me!M1 = Me!M1
End If
' Check my Ball 5 to winning ball 1
If CInt(Me!C5) = Me!B1 Then
Me!M1 = Me!B1
CountNum = CountNum + 1
Else
Me!M1 = Me!M1
End If
' Check my Ball 6 to winning ball 1
If CInt(Me!C6) = Me!B1 Then
Me!M1 = Me!B1
CountNum = CountNum + 1
Else
Me!M1 = Me!M1
End If
' Check my Ball 1 to winning ball 2
If CInt(Me!C1) = Me!B2 Then
Me!M2 = Me!B2
CountNum = CountNum + 1
Else
Me!M2 = Me!M2
End If
' Check my Ball 2 to winning ball 2
If CInt(Me!C2) = Me!B2 Then
Me!M2 = Me!B2
CountNum = CountNum + 1
Else
Me!M2 = Me!M2
End If
' Check my Ball 3 to winning ball 2
If CInt(Me!C3) = Me!B2 Then
Me!M2 = Me!B2
CountNum = CountNum + 1
Else
Me!M2 = Me!M2
End If
' Check my Ball 4 to winning ball 2
If CInt(Me!C4) = Me!B2 Then
Me!M2 = Me!B2
CountNum = CountNum + 1
Else
Me!M2 = Me!M2
End If
' Check my Ball 5 to winning ball 2
If CInt(Me!C5) = Me!B2 Then
Me!M2 = Me!B2
CountNum = CountNum + 1
Else
Me!M2 = Me!M2
End If
' Check my Ball 6 to winning ball 2
If CInt(Me!C6) = Me!B2 Then
Me!M2 = Me!B2
CountNum = CountNum + 1
Else
Me!M2 = Me!M2
End If
' Check my Ball 1 to winning ball 3
If CInt(Me!C1) = Me!B3 Then
Me!M3 = Me!B3
CountNum = CountNum + 1
Else
Me!M3 = Me!M3
End If
' Check my Ball 2 to winning ball 3
If CInt(Me!C2) = Me!B3 Then
Me!M3 = Me!B3
CountNum = CountNum + 1
Else
Me!M3 = Me!M3
End If
' Check my Ball 3 to winning ball 3
If CInt(Me!C3) = Me!B3 Then
Me!M3 = Me!B3
CountNum = CountNum + 1
Else
Me!M3 = Me!M3
End If
' Check my Ball 4 to winning ball 3
If CInt(Me!C4) = Me!B3 Then
Me!M3 = Me!B3
CountNum = CountNum + 1
Else
Me!M3 = Me!M3
End If
' Check my Ball 5 to winning ball 3
If CInt(Me!C5) = Me!B3 Then
Me!M3 = Me!B3
CountNum = CountNum + 1
Else
Me!M3 = Me!M3
End If
' Check my Ball 6 to winning ball 3
If CInt(Me!C6) = Me!B1 Then
Me!M3 = Me!B3
CountNum = CountNum + 1
Else
Me!M3 = Me!M3
End If
'''' Check my Ball 1 to winning ball 4
If CInt(Me!C1) = Me!B4 Then
Me!M4 = Me!B4
CountNum = CountNum + 1
Else
Me!M4 = Me!M4
End If
' Check my Ball 2 to winning ball 4
If CInt(Me!C2) = Me!B4 Then
Me!M4 = Me!B4
CountNum = CountNum + 1
Else
Me!M4 = Me!M4
End If
' Check my Ball 3 to winning ball 4
If CInt(Me!C3) = Me!B4 Then
Me!M4 = Me!B4
CountNum = CountNum + 1
Else
Me!M4 = Me!M4
End If
' Check my Ball 4 to winning ball 4
If CInt(Me!C4) = Me!B4 Then
Me!M4 = Me!B4
CountNum = CountNum + 1
Else
Me!M4 = Me!M4
End If
' Check my Ball 5 to winning ball 4
If CInt(Me!C5) = Me!B4 Then
Me!M4 = Me!B4
CountNum = CountNum + 1
Else
Me!M4 = Me!M4
End If
' Check my Ball 6 to winning ball 4
If CInt(Me!C6) = Me!B4 Then
Me!M4 = Me!B4
CountNum = CountNum + 1
Else
Me!M4 = Me!M4
End If
' Check my Ball 1 to winning ball 5
If CInt(Me!C1) = Me!B5 Then
Me!M5 = Me!B5
CountNum = CountNum + 1
Else
Me!M5 = Me!M5
End If
' Check my Ball 2 to winning ball 5
If CInt(Me!C2) = Me!B5 Then
Me!M5 = Me!B5
CountNum = CountNum + 1
Else
Me!M5 = Me!M5
End If
' Check my Ball 3 to winning ball 5
If CInt(Me!C3) = Me!B5 Then
Me!M5 = Me!B5
CountNum = CountNum + 1
Else
Me!M5 = Me!M5
End If
' Check my Ball 4 to winning ball 5
If CInt(Me!C4) = Me!B5 Then
Me!M5 = Me!B5
CountNum = CountNum + 1
Else
Me!M5 = Me!M5
End If
' Check my Ball 5 to winning ball 5
If CInt(Me!C5) = Me!B5 Then
Me!M5 = Me!B5
CountNum = CountNum + 1
Else
Me!M5 = Me!M5
End If
' Check my Ball 6 to winning ball 5
If CInt(Me!C6) = Me!B5 Then
Me!M5 = Me!B5
CountNum = CountNum + 1
Else
Me!M5 = Me!M5
End If
' Check my Ball 1 to winning ball 6
If CInt(Me!C1) = Me!B6 Then
Me!M6 = Me!B6
CountNum = CountNum + 1
Else
Me!M6 = Me!M6
End If
' Check my Ball 2 to winning ball 6
If CInt(Me!C2) = Me!B6 Then
Me!M6 = Me!B6
CountNum = CountNum + 1
Else
Me!M6 = Me!M6
End If
' Check my Ball 3 to winning ball 6
If CInt(Me!C3) = Me!B6 Then
Me!M6 = Me!B6
CountNum = CountNum + 1
Else
Me!M6 = Me!M6
End If
' Check my Ball 4 to winning ball 6
If CInt(Me!C4) = Me!B6 Then
Me!M6 = Me!B6
CountNum = CountNum + 1
Else
Me!M6 = Me!M6
End If
' Check my Ball 5 to winning ball 6
If CInt(Me!C5) = Me!B6 Then
Me!M6 = Me!B6
CountNum = CountNum + 1
Else
Me!M6 = Me!M6
End If
' Check my Ball 6 to winning ball 6
If CInt(Me!C6) = Me!B6 Then
Me!M6 = Me!B6
CountNum = CountNum + 1
Else
Me!M6 = Me!M6
End If
' Check my Ball 1 to winning ball BB
If CInt(Me!C1) = Me!BB Then
Me!MB = Me!BB
Me!AndBonus.Visible = True
Else
Me!MB = Me!MB
End If
' Check my Ball 2 to winning ball BB
If CInt(Me!C2) = Me!BB Then
Me!MB = Me!BB
Me!AndBonus.Visible = True
Else
Me!MB = Me!MB
End If
' Check my Ball 3 to winning ball BB
If CInt(Me!C3) = Me!BB Then
Me!MB = Me!BB
Me!AndBonus.Visible = True
Else
Me!MB = Me!MB
End If
' Check my Ball 4 to winning ball BB
If CInt(Me!C4) = Me!BB Then
Me!MB = Me!BB
Me!AndBonus.Visible = True
Else
Me!MB = Me!MB
'End If
' Check my Ball 5 to winning ball BB
If CInt(Me!C5) = Me!BB Then
Me!MB = Me!BB
Me!AndBonus.Visible = True
Else
Me!MB = Me!MB
End If
' Check my Ball 6 to winning ball BB
If CInt(Me!C6) = Me!BB Then
Me!MB = Me!BB
Me!AndBonus.Visible = True
Else
Me!MB = Me!MB
End If
'End If
Me!CountNums = CountNum
'Check Winnings
If Me!CountNums = 6 And Me!Div1NumWin = 0 Then
Me!Winnings = Me!Winnings
End If
If Me!CountNums = 6 And Me!Div1NumWin > 0 Then
Me!Winnings = Me!Div1 / Me!Div1NumWin
Else
Me!Winnings = Me!Winnings
If Me!CountNums = 5 And Me!AndBonus.Visible = True Then
Me!Winnings = Me!Div2 / 1
Else
Me!Winnings = Me!Winnings
End If
If Me!CountNums = 5 And Me!AndBonus.Visible = False Then
Me!Winnings = Me!Div3 / 1
Else
Me!Winnings = Me!Winnings
End If
If Me!CountNums = 4 And Me!AndBonus.Visible = True Then
Me!Winnings = Me!Div4 / 1
Else
Me!Winnings = Me!Winnings
End If
If Me!CountNums = 4 And Me!AndBonus.Visible = False Then
Me!Winnings = Me!Div5 / 1
Else
Me!Winnings = Me!Winnings
End If
If Me!CountNums = 3 And Me!AndBonus.Visible = True Then
Me!Winnings = Me!Div6 / 1
Else
Me!Winnings = Me!Winnings
End If
If Me!CountNums = 3 And Me!AndBonus.Visible = False Then
Me!Winnings = Me!Div7 / 1
Else
Me!Winnings = Me!Winnings
End If
DoCmd.OpenForm "WinningAmounts", acNormal, , , acFormAdd, acHidden
Forms![WinningAmounts].[Amount] = Forms![Check numbers against all winning numbers].[Winnings]
DoCmd.Close acForm, "WinningAmounts"
DoCmd.GoToRecord , , acNext
Counter = Counter + 1
If Counter = 404 Then
Check = False
Exit Do
End If
Loop
Loop Until Check = False
End Sub
Dim Check, Counter
Check = True: Counter = 0 ' Initialize variables.
Do ' Outer loop.
Do While Counter < 20 ' Inner loop.
Counter = Counter + 1 ' Increment Counter.
If Counter = 10 Then ' If condition is True.
Check = False ' Set value of flag to False.
Exit Do ' Exit inner loop.
End If
Loop
Loop Until Check = False ' Exit outer loop immediately
works great!
BUT
When I insert the rest of my code in between and execute it tells me there is a compile error: Loop without Do
This is what that code looks like:
Private Sub Check_Click()
Dim Check, Counter
Dim CountNum As Integer
Check = True: Counter = 0 ' Initialize variables.
Do
Do While Counter < 405
'Set Winning Amount to zero
Me!Winnings = 0
' Set label + Bonus to not visible
Me!AndBonus.Visible = False
' Set the counter to zero
CountNum = 0
' Set all winning fields to empty
Me!M1 = ""
Me!M2 = ""
Me!M3 = ""
Me!M4 = ""
Me!M5 = ""
Me!M6 = ""
Me!MB = ""
' Check That a valid date has been selected
If IsNull(Me!DrawDate) Then
MsgBox "Please select a valid date!", vbCritical, "Select a valid date!"
Exit Sub
End If
' Check all fields are filled in
If IsNull(CInt(Me!C1)) Or IsNull(CInt(Me!C2)) Or IsNull(CInt(Me!C3)) Or IsNull(CInt(Me!C4)) Or IsNull(CInt(Me!C5)) Or IsNull(CInt(Me!C6)) Then
MsgBox "All 6 fields must be filled in!", vbCritical, "Complete all numbers!"
Exit Sub
End If
' Check my Ball 1 to winning ball 1
If CInt(Me!C1) = Me!B1 Then
Me!M1 = Me!B1
CountNum = CountNum + 1
Else
Me!M1 = Me!M1
End If
' Check my Ball 2 to winning ball 1
If CInt(Me!C2) = Me!B1 Then
Me!M1 = Me!B1
CountNum = CountNum + 1
Else
Me!M1 = Me!M1
End If
' Check my Ball 3 to winning ball 1
If CInt(Me!C3) = Me!B1 Then
Me!M1 = Me!B1
CountNum = CountNum + 1
Else
Me!M1 = Me!M1
End If
' Check my Ball 4 to winning ball 1
If CInt(Me!C4) = Me!B1 Then
Me!M1 = Me!B1
CountNum = CountNum + 1
Else
Me!M1 = Me!M1
End If
' Check my Ball 5 to winning ball 1
If CInt(Me!C5) = Me!B1 Then
Me!M1 = Me!B1
CountNum = CountNum + 1
Else
Me!M1 = Me!M1
End If
' Check my Ball 6 to winning ball 1
If CInt(Me!C6) = Me!B1 Then
Me!M1 = Me!B1
CountNum = CountNum + 1
Else
Me!M1 = Me!M1
End If
' Check my Ball 1 to winning ball 2
If CInt(Me!C1) = Me!B2 Then
Me!M2 = Me!B2
CountNum = CountNum + 1
Else
Me!M2 = Me!M2
End If
' Check my Ball 2 to winning ball 2
If CInt(Me!C2) = Me!B2 Then
Me!M2 = Me!B2
CountNum = CountNum + 1
Else
Me!M2 = Me!M2
End If
' Check my Ball 3 to winning ball 2
If CInt(Me!C3) = Me!B2 Then
Me!M2 = Me!B2
CountNum = CountNum + 1
Else
Me!M2 = Me!M2
End If
' Check my Ball 4 to winning ball 2
If CInt(Me!C4) = Me!B2 Then
Me!M2 = Me!B2
CountNum = CountNum + 1
Else
Me!M2 = Me!M2
End If
' Check my Ball 5 to winning ball 2
If CInt(Me!C5) = Me!B2 Then
Me!M2 = Me!B2
CountNum = CountNum + 1
Else
Me!M2 = Me!M2
End If
' Check my Ball 6 to winning ball 2
If CInt(Me!C6) = Me!B2 Then
Me!M2 = Me!B2
CountNum = CountNum + 1
Else
Me!M2 = Me!M2
End If
' Check my Ball 1 to winning ball 3
If CInt(Me!C1) = Me!B3 Then
Me!M3 = Me!B3
CountNum = CountNum + 1
Else
Me!M3 = Me!M3
End If
' Check my Ball 2 to winning ball 3
If CInt(Me!C2) = Me!B3 Then
Me!M3 = Me!B3
CountNum = CountNum + 1
Else
Me!M3 = Me!M3
End If
' Check my Ball 3 to winning ball 3
If CInt(Me!C3) = Me!B3 Then
Me!M3 = Me!B3
CountNum = CountNum + 1
Else
Me!M3 = Me!M3
End If
' Check my Ball 4 to winning ball 3
If CInt(Me!C4) = Me!B3 Then
Me!M3 = Me!B3
CountNum = CountNum + 1
Else
Me!M3 = Me!M3
End If
' Check my Ball 5 to winning ball 3
If CInt(Me!C5) = Me!B3 Then
Me!M3 = Me!B3
CountNum = CountNum + 1
Else
Me!M3 = Me!M3
End If
' Check my Ball 6 to winning ball 3
If CInt(Me!C6) = Me!B1 Then
Me!M3 = Me!B3
CountNum = CountNum + 1
Else
Me!M3 = Me!M3
End If
'''' Check my Ball 1 to winning ball 4
If CInt(Me!C1) = Me!B4 Then
Me!M4 = Me!B4
CountNum = CountNum + 1
Else
Me!M4 = Me!M4
End If
' Check my Ball 2 to winning ball 4
If CInt(Me!C2) = Me!B4 Then
Me!M4 = Me!B4
CountNum = CountNum + 1
Else
Me!M4 = Me!M4
End If
' Check my Ball 3 to winning ball 4
If CInt(Me!C3) = Me!B4 Then
Me!M4 = Me!B4
CountNum = CountNum + 1
Else
Me!M4 = Me!M4
End If
' Check my Ball 4 to winning ball 4
If CInt(Me!C4) = Me!B4 Then
Me!M4 = Me!B4
CountNum = CountNum + 1
Else
Me!M4 = Me!M4
End If
' Check my Ball 5 to winning ball 4
If CInt(Me!C5) = Me!B4 Then
Me!M4 = Me!B4
CountNum = CountNum + 1
Else
Me!M4 = Me!M4
End If
' Check my Ball 6 to winning ball 4
If CInt(Me!C6) = Me!B4 Then
Me!M4 = Me!B4
CountNum = CountNum + 1
Else
Me!M4 = Me!M4
End If
' Check my Ball 1 to winning ball 5
If CInt(Me!C1) = Me!B5 Then
Me!M5 = Me!B5
CountNum = CountNum + 1
Else
Me!M5 = Me!M5
End If
' Check my Ball 2 to winning ball 5
If CInt(Me!C2) = Me!B5 Then
Me!M5 = Me!B5
CountNum = CountNum + 1
Else
Me!M5 = Me!M5
End If
' Check my Ball 3 to winning ball 5
If CInt(Me!C3) = Me!B5 Then
Me!M5 = Me!B5
CountNum = CountNum + 1
Else
Me!M5 = Me!M5
End If
' Check my Ball 4 to winning ball 5
If CInt(Me!C4) = Me!B5 Then
Me!M5 = Me!B5
CountNum = CountNum + 1
Else
Me!M5 = Me!M5
End If
' Check my Ball 5 to winning ball 5
If CInt(Me!C5) = Me!B5 Then
Me!M5 = Me!B5
CountNum = CountNum + 1
Else
Me!M5 = Me!M5
End If
' Check my Ball 6 to winning ball 5
If CInt(Me!C6) = Me!B5 Then
Me!M5 = Me!B5
CountNum = CountNum + 1
Else
Me!M5 = Me!M5
End If
' Check my Ball 1 to winning ball 6
If CInt(Me!C1) = Me!B6 Then
Me!M6 = Me!B6
CountNum = CountNum + 1
Else
Me!M6 = Me!M6
End If
' Check my Ball 2 to winning ball 6
If CInt(Me!C2) = Me!B6 Then
Me!M6 = Me!B6
CountNum = CountNum + 1
Else
Me!M6 = Me!M6
End If
' Check my Ball 3 to winning ball 6
If CInt(Me!C3) = Me!B6 Then
Me!M6 = Me!B6
CountNum = CountNum + 1
Else
Me!M6 = Me!M6
End If
' Check my Ball 4 to winning ball 6
If CInt(Me!C4) = Me!B6 Then
Me!M6 = Me!B6
CountNum = CountNum + 1
Else
Me!M6 = Me!M6
End If
' Check my Ball 5 to winning ball 6
If CInt(Me!C5) = Me!B6 Then
Me!M6 = Me!B6
CountNum = CountNum + 1
Else
Me!M6 = Me!M6
End If
' Check my Ball 6 to winning ball 6
If CInt(Me!C6) = Me!B6 Then
Me!M6 = Me!B6
CountNum = CountNum + 1
Else
Me!M6 = Me!M6
End If
' Check my Ball 1 to winning ball BB
If CInt(Me!C1) = Me!BB Then
Me!MB = Me!BB
Me!AndBonus.Visible = True
Else
Me!MB = Me!MB
End If
' Check my Ball 2 to winning ball BB
If CInt(Me!C2) = Me!BB Then
Me!MB = Me!BB
Me!AndBonus.Visible = True
Else
Me!MB = Me!MB
End If
' Check my Ball 3 to winning ball BB
If CInt(Me!C3) = Me!BB Then
Me!MB = Me!BB
Me!AndBonus.Visible = True
Else
Me!MB = Me!MB
End If
' Check my Ball 4 to winning ball BB
If CInt(Me!C4) = Me!BB Then
Me!MB = Me!BB
Me!AndBonus.Visible = True
Else
Me!MB = Me!MB
'End If
' Check my Ball 5 to winning ball BB
If CInt(Me!C5) = Me!BB Then
Me!MB = Me!BB
Me!AndBonus.Visible = True
Else
Me!MB = Me!MB
End If
' Check my Ball 6 to winning ball BB
If CInt(Me!C6) = Me!BB Then
Me!MB = Me!BB
Me!AndBonus.Visible = True
Else
Me!MB = Me!MB
End If
'End If
Me!CountNums = CountNum
'Check Winnings
If Me!CountNums = 6 And Me!Div1NumWin = 0 Then
Me!Winnings = Me!Winnings
End If
If Me!CountNums = 6 And Me!Div1NumWin > 0 Then
Me!Winnings = Me!Div1 / Me!Div1NumWin
Else
Me!Winnings = Me!Winnings
If Me!CountNums = 5 And Me!AndBonus.Visible = True Then
Me!Winnings = Me!Div2 / 1
Else
Me!Winnings = Me!Winnings
End If
If Me!CountNums = 5 And Me!AndBonus.Visible = False Then
Me!Winnings = Me!Div3 / 1
Else
Me!Winnings = Me!Winnings
End If
If Me!CountNums = 4 And Me!AndBonus.Visible = True Then
Me!Winnings = Me!Div4 / 1
Else
Me!Winnings = Me!Winnings
End If
If Me!CountNums = 4 And Me!AndBonus.Visible = False Then
Me!Winnings = Me!Div5 / 1
Else
Me!Winnings = Me!Winnings
End If
If Me!CountNums = 3 And Me!AndBonus.Visible = True Then
Me!Winnings = Me!Div6 / 1
Else
Me!Winnings = Me!Winnings
End If
If Me!CountNums = 3 And Me!AndBonus.Visible = False Then
Me!Winnings = Me!Div7 / 1
Else
Me!Winnings = Me!Winnings
End If
DoCmd.OpenForm "WinningAmounts", acNormal, , , acFormAdd, acHidden
Forms![WinningAmounts].[Amount] = Forms![Check numbers against all winning numbers].[Winnings]
DoCmd.Close acForm, "WinningAmounts"
DoCmd.GoToRecord , , acNext
Counter = Counter + 1
If Counter = 404 Then
Check = False
Exit Do
End If
Loop
Loop Until Check = False
End Sub