if and statement

P

Pawdnos

Could anybody please tell me why this code doesn't work when I use the "And"
to validate the next field on the form.

Private Sub TotalMasteringCost_AfterUpdate()
If Me.ChargeTo.Value = "Paul" And Me.TotalMasteringCost.Value > 0 Then

Me.WHV_.Value = Me.TotalMasteringCost / 2
Me.Corp_.Value = Me.TotalMasteringCost / 2
Else:
Me.WHV_.Value = 0
Me.Corp_.Value = 0
End If

End Sub
 
D

Douglas J. Steele

What does "doesn't work" mean? What happens when your code runs? What should
happen?
 
J

Jeff Boyce

I believe your "And" tells Access to do a logical comparison.

I think what you want to do may be something more like:

If Me!ChangeTo = "Paul" Then
If Me!TotalMasteringCost > 0 Then
'do this
'and this
Else
Else
'do that
End If

Regards

Jeff Boyce
Microsoft Office/Access MVP
 
D

Douglas J. Steele

Or

If (Me.ChargeTo.Value = "Paul") And (Me.TotalMasteringCost.Value > 0) Then
Me.WHV_.Value = Me.TotalMasteringCost / 2
Me.Corp_.Value = Me.TotalMasteringCost / 2
Else
Me.WHV_.Value = 0
Me.Corp_.Value = 0
End If

(Jeff: you left out an End If)
 
J

Jeff Boyce

But only one?!? (<whine>)

Jeff

Douglas J. Steele said:
Or

If (Me.ChargeTo.Value = "Paul") And (Me.TotalMasteringCost.Value > 0)
Then
Me.WHV_.Value = Me.TotalMasteringCost / 2
Me.Corp_.Value = Me.TotalMasteringCost / 2
Else
Me.WHV_.Value = 0
Me.Corp_.Value = 0
End If

(Jeff: you left out an End If)
 
Top