The report which utilises the code below is based on a query which returns up to four records, the top two teams competing for Honours Only (HO) and the top two who are not HO. If there is only one team competing as HO, the query will return only three records and if there are no teams competing as HO, then only two records are returned.
This code assumes there are four records all the time:
In order to make the code adjust to suit the number of records, I added a text box named “Count” to the report, which has a Control Source “=Count(*)”. This returns the number of records. As the number of teams reduces, the “Placing” will change, so I need to create a code that looks at IntCount as well as IntPlacing.
If we ignore the BooHO part of the argument for the moment, the argument is as follows:
If IntCount = 4 and IntPosition = 4 Then Placing = “Winner”.
If IntCount = 4 and IntPosition = 3 Then Placing = “Second Place”
If IntCount = 3 and IntPosition = 3 Then Placing = “Winner”.
If IntCount = 3 and IntPosition = 2 Then Placing = “Second Place”
If IntCount = 2 and IntPosition = 2 Then Placing = “Winner”.
If IntCount = 2 and IntPosition = 2 Then Placing = “Second Place”
My modified code currently looks like this:
The query is currently returning 3 records and, if I run the code in the immediately window I get the correct answer. However, when I open the report, I see three records but the Text Box “Placing is blank”.
I would be grateful if someone could take a look and advise me why this should be.
Thanks a lot
John
This code assumes there are four records all the time:
Code:
Public Function Placing(IntPosition As Integer, _
BooHO As Boolean) As String
Select Case IntPosition
Case 4
If BooHO Then Placing = "Actual Winner" Else Placing = "Winner"
Case 3
If BooHO Then Placing = "Actual Second Place" Else Placing = "Second Place"
Case 2
If BooHO Then Placing = "Actual Third Place" Else Placing = "Third Place"
End Select
Select Case IntPosition
Case 3
If BooHO Then Placing = "Actual Winner" Else Placing = "Winner"
Case 2
If BooHO Then Placing = "Actual Second Place" Else Placing = "Second Place"
Case 1
If BooHO Then Placing = "Actual Third Place" Else Placing = "Third Place"
End Select
End Function
If we ignore the BooHO part of the argument for the moment, the argument is as follows:
If IntCount = 4 and IntPosition = 4 Then Placing = “Winner”.
If IntCount = 4 and IntPosition = 3 Then Placing = “Second Place”
If IntCount = 3 and IntPosition = 3 Then Placing = “Winner”.
If IntCount = 3 and IntPosition = 2 Then Placing = “Second Place”
If IntCount = 2 and IntPosition = 2 Then Placing = “Winner”.
If IntCount = 2 and IntPosition = 2 Then Placing = “Second Place”
My modified code currently looks like this:
Code:
Public Function Placing_2(IntPosition As Integer, _
BooHO As Boolean, IntCount As Integer) As String
Select Case IntCount
Case 4
Select Case IntPosition
Case 4
If BooHO Then Placing_2 = "Actual Winner" Else Placing_2 = "Winner"
Case 3
If BooHO Then Placing_2 = "Actual Second Place" Else Placing_2 = "Second Place"
Case 2
If BooHO Then Placing_2 = "Actual Third Place" Else Placing_2 = "Third Place"
End Select
End Select
Select Case IntCount
Case 3
Select Case IntPosition
Case 3
If BooHO Then Placing_2 = "Actual Winner" Else Placing_2 = "Winner"
Case 2
If BooHO Then Placing_2 = "Actual Second Place" Else Placing_2 = "Second Place"
Case 1
If BooHO Then Placing_2 = "Actual Third Place" Else Placing_2 = "Third Place"
End Select
End Select
End Function
I would be grateful if someone could take a look and advise me why this should be.
Thanks a lot
John