if and statement

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
What does "doesn't work" mean? What happens when your code runs? What should
happen?
 
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
 
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)
 
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)
 

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

Back
Top