If...Then...Else Help....

M

Michelle

I have the following...and can not figure out why it does not work.
Private Sub HeatPoints_BeforeUpdate(Cancel As Integer)
If (Me.HeatPlace.Value = "1") Then
Me.HeatPoints.Value = "5"
Else
If (Me.HeatPlace.Value = "2") Then
Me.HeatPoints.Value = "4"
Else
If (Me.HeatPlace.Value = "3") Then
Me.HeatPoints.Value = "3"
Else
If (Me.HeatPlace.Value = "4") Then
Me.HeatPoints.Value = "2"
Else
If (Me.HeatPlace.Value = "5") Then
Me.HeatPoints.Value = "1"
Else
If (Me.HeatPlace.Value > "5") Then
Me.HeatPoints.Value = "0"
Else
If (Me.HeatPlace.Value = "DNF") Then
Me.HeatPoints.Value = "0"
Else
If (Me.HeatPlace.Value = "DNS") Then
Me.HeatPoints.Value = "0"
End If
End Sub
 
K

Karl E. Peterson

Michelle said:
I have the following...and can not figure out why it does not work.

Well, define "does not work"?

But hey, just for kicks, have you tried walking through it with the F8 key?
For example, what would you expect (define as "works") if the initial value
of Me.HeatPoints.Value is 1? To me, it appears the code would set it to,
drumbeat..., 1!
Private Sub HeatPoints_BeforeUpdate(Cancel As Integer)
If (Me.HeatPlace.Value = "1") Then
Me.HeatPoints.Value = "5"
Else
If (Me.HeatPlace.Value = "2") Then
Me.HeatPoints.Value = "4"
Else
If (Me.HeatPlace.Value = "3") Then
Me.HeatPoints.Value = "3"
Else
If (Me.HeatPlace.Value = "4") Then
Me.HeatPoints.Value = "2"
Else
If (Me.HeatPlace.Value = "5") Then
Me.HeatPoints.Value = "1"
Else
If (Me.HeatPlace.Value > "5") Then
Me.HeatPoints.Value = "0"
Else
If (Me.HeatPlace.Value = "DNF") Then
Me.HeatPoints.Value = "0"
Else
If (Me.HeatPlace.Value = "DNS") Then
Me.HeatPoints.Value = "0"
End If
End Sub

Best suggestion would be to use a Select Case statement, rather than a
series of If statements. (You're setting, then resetting, things.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top