G
Guest
I'm using Access 2003, and I want to be able to simplify a very repetitious
bit of code by calling a sub with two input numbers. This is for a
scoreboard program I am doing in Access, using VBA to calculate the new
totals. There are three teams and three players on each team, and I want to
be able to just do something like Score(1, 1) for the first player on the
first team.
Here is what my code is like at the moment. It works if I do it directly
rather than calling the sub and having it do the concatenating, but I can't
use it this way because in concatenating the parts, everything turns to
strings. Is there any way to fix that, or do I just have to work around it
another way?
Public Sub Right(Team As String, Player As String)
'First read the Team and Player to reference TeamX_PlayerXScore
'which is where the score is added to the player's total
ThisPlayer = "Team" & Team & "_Player" & Player & "Score"
'Now create a reference to the location where the team score is posted
'with the format TXScoreboard
ThisTeam = "T" & Team & "Scoreboard"
'Now create a reference to the field where the team total for the round is
saved
'with the format TXScore
ThisScore = "T" & Team & "Score"
'Using the references, attempt to make the calculations
'InputHere is the score for the current question, and is identified
'at the point when the input box loses focus
ThisScore = ThisScore + InputHere
ThisPlayer = ThisPlayer + InputHere
ThisTeam.Value = CStr(ThisScore)
'The problem is that of course it sees ThisPlayer, ThisTeam, and ThisScore
'as strings instead of as references to fields and text boxes.
End Sub
SSB
bit of code by calling a sub with two input numbers. This is for a
scoreboard program I am doing in Access, using VBA to calculate the new
totals. There are three teams and three players on each team, and I want to
be able to just do something like Score(1, 1) for the first player on the
first team.
Here is what my code is like at the moment. It works if I do it directly
rather than calling the sub and having it do the concatenating, but I can't
use it this way because in concatenating the parts, everything turns to
strings. Is there any way to fix that, or do I just have to work around it
another way?
Public Sub Right(Team As String, Player As String)
'First read the Team and Player to reference TeamX_PlayerXScore
'which is where the score is added to the player's total
ThisPlayer = "Team" & Team & "_Player" & Player & "Score"
'Now create a reference to the location where the team score is posted
'with the format TXScoreboard
ThisTeam = "T" & Team & "Scoreboard"
'Now create a reference to the field where the team total for the round is
saved
'with the format TXScore
ThisScore = "T" & Team & "Score"
'Using the references, attempt to make the calculations
'InputHere is the score for the current question, and is identified
'at the point when the input box loses focus
ThisScore = ThisScore + InputHere
ThisPlayer = ThisPlayer + InputHere
ThisTeam.Value = CStr(ThisScore)
'The problem is that of course it sees ThisPlayer, ThisTeam, and ThisScore
'as strings instead of as references to fields and text boxes.
End Sub
SSB