After Update help needed

  • Thread starter Thread starter DubboPete
  • Start date Start date
D

DubboPete

Hi all,

It's me and my basketball project again...

I have a form which lists the fixtures for the current round, and I am
trying to update two fields depending on the results.

Imagine we have Team A and Team B playing a fixture. Both teams turn up at
the appointed time, so neither team forfeits the result.

I enter Team A's score of 25, and then Team B's score of 10.
I would like Team A's points to tally 3, and Team B's team to tally 1

Note, in the instance of one team not turning up, therefore forfeiting the
fixture, the [forfeit] option button for that team is clicked, and the team
that did turn up gets 3 points, and the forfeiting team gets 0. In that
event, scores are not required, because obviously there are no scores....

Fields:

[TeamA] is a numeric field
[TeamB] is a numeric field

[Ascore] is numeric
[Bscore] is numeric

[AForfeit] is an option button, for a Yes/No field
[BForfeit] is an option button, for a Yes/No field

[APts] is numeric
[BPts] is numeric

I thought I had cracked it here, but it don't update fields [APts] and
[BPts].
Here's the code


Private Sub B_Pts_AfterUpdate()

If Not IsNull(Me.[AForfeit]) Then
Me.[APts] = 0 'Team A forfeited
Me.[BPts] = 3 'Team B collect the three points
ElseIf Not IsNull(Me.BForfeit) Then
Me.[BPts] = 0 'Team B forfeited
Me.[APts] = 3 'Team A collect the three points
Else
If (CInt(Me.[APts])) > (CInt(Me.[BPts])) Then
Me.[APts] = 3 'Team A won
Me.[BPts] = 1 'Team B lost
ElseIf (CInt(Me.[APts])) < (CInt(Me.[BPts])) Then
Me.[APts] = 1 'Team A lost
Me.[BPts] = 3 'Team B won
Else
Me.[APts] = 1 'drawn game
Me.[BPts] = 1 'drawn game
End If
End If

End Sub


I think that I may be going wrong with the option button part, but I am not
sure...

or maybe I am using "If ... Then ... Else" when it should really be a "Case
Select" code?

Anyone care to guide me back to the true path of the wisdom of VBA coding?

thanks much in anticipation

DubboPete
 
DubboPete said:
Hi all,

It's me and my basketball project again...

I have a form which lists the fixtures for the current round, and I am
trying to update two fields depending on the results.

Imagine we have Team A and Team B playing a fixture. Both teams turn up at
the appointed time, so neither team forfeits the result.

I enter Team A's score of 25, and then Team B's score of 10.
I would like Team A's points to tally 3, and Team B's team to tally 1

Note, in the instance of one team not turning up, therefore forfeiting the
fixture, the [forfeit] option button for that team is clicked, and the team
that did turn up gets 3 points, and the forfeiting team gets 0. In that
event, scores are not required, because obviously there are no scores....

Fields:

[TeamA] is a numeric field
[TeamB] is a numeric field

[Ascore] is numeric
[Bscore] is numeric

[AForfeit] is an option button, for a Yes/No field
[BForfeit] is an option button, for a Yes/No field

[APts] is numeric
[BPts] is numeric

I thought I had cracked it here, but it don't update fields [APts] and
[BPts].
Here's the code


Private Sub B_Pts_AfterUpdate()

If Not IsNull(Me.[AForfeit]) Then
Me.[APts] = 0 'Team A forfeited
Me.[BPts] = 3 'Team B collect the three points
ElseIf Not IsNull(Me.BForfeit) Then
Me.[BPts] = 0 'Team B forfeited
Me.[APts] = 3 'Team A collect the three points
Else
If (CInt(Me.[APts])) > (CInt(Me.[BPts])) Then
Me.[APts] = 3 'Team A won
Me.[BPts] = 1 'Team B lost
ElseIf (CInt(Me.[APts])) < (CInt(Me.[BPts])) Then
Me.[APts] = 1 'Team A lost
Me.[BPts] = 3 'Team B won
Else
Me.[APts] = 1 'drawn game
Me.[BPts] = 1 'drawn game
End If
End If

End Sub


I think that I may be going wrong with the option button part, but I am not
sure...

or maybe I am using "If ... Then ... Else" when it should really be a "Case
Select" code?

Anyone care to guide me back to the true path of the wisdom of VBA coding?

thanks much in anticipation

DubboPete

This is kind of like the blind leading the blind <g>, but I'll give it a
try.

The code is not updating [APts] because it should be called in the
afterupdate event of [Ascore] - [Bscore], not [APts] - [BPts]


After reading your post, it appears that:

[TeamA] and [TeamB] are the FK to the team's name.

[Ascore] and [Bscore] are the ending scores

[APts] and [BPts] (or is it [A_Pts]and [B_Pts]?) are to calculate the
season winner.
---

**Since [APts] and [BPts] can be calculated anytime (kind of like
totals), I think this should be done in a query when printing a report
or on a summary form.

But..... to continue, as far as your code, try these changes:

CInt() is not needed because there cannot be a score of 26.5; the last I
knew basketball points were integer only.


I would have sub that awards the points called in three places: in
[Ascore] and [Bscore] AfterUpdate events and the form OnCurrent event.

'******** begin AIR code *************
Private Sub Form_Current()
AwardPoints
End Sub


Private Sub Ascore_AfterUpdate()
AwardPoints
End Sub


Private Sub Bscore_AfterUpdate()
AwardPoints
End Sub


Private Sub AwardPoints()

If Me.[AForfeit] = True Then
Me.[APts] = 0 'Team A forfeited
Me.[BPts] = 3 'Team B collect the three points
ElseIf Me.BForfeit = True Then
Me.[BPts] = 0 'Team B forfeited
Me.[APts] = 3 'Team A collect the three points
Else
If Me.[Ascore] > Me.[Bscore] Then
Me.[APts] = 3 'Team A won
Me.[BPts] = 1 'Team B lost
ElseIf Me.[Ascore] < Me.[Bscore] Then
Me.[APts] = 1 'Team A lost
Me.[BPts] = 3 'Team B won
Else
Me.[APts] = 1 'drawn game
Me.[BPts] = 1 'drawn game
End If
End If

End Sub
'******** end AIR code *************

[AForfeit] and [BForfeit] are boolean fields, they should default to
FALSE. The only way they would be TRUE is if you clicked the forfeit
button. BTW, can *both* teams forfeit?


Am I close to the path?? <g>
 
Back
Top