There is a syntax error in the If statement at the Else part.
If (Me.[Text123] + Me.[Text125] + Me.[Text126]) < 5000 Then
Me.[Director Approval].Enabled = False
Me.[Dir Signature].Enabled = False
Me![Dir Current Date].Enabled = False
Else
Me.[Director Approval].Enabled = True
Me.[Dir Signature].Enabled = True
Me![Dir Current Date].Enabled = True
End If
If it's not less than, then it is greater than or equal to, so an Else is
all you need. I noticed also that for [Dir Current Date] you have used
'!'
instead of '.'. This may cause you a problem in some cases if the field
and
control have the same name.
Are any of the values Null? If so, then adding them together will give
Null
as a result. Null propagates through an expression. Try changing the If
line
to:
If (Nz(Me.[Text123], 0) + Nz(Me.[Text125], 0) + Nz(Me.[Text126], 0)) <
5000
Then
This will add 0 if the value is Null.
You are correct, you need the Else, without it, once you've grayed out
the
boxes, they will stay that way until you close and open the form.
--
Wayne Morgan
MS Access MVP
Bryan said:
Still does not work, Wayne. This is what I have now:
Private Sub Form_Current()
If (Me.[Text123] + Me.[Text125] + Me.[Text126]) < 5000 Then
Me.[Director Approval].Enabled = False
Me.[Dir Signature].Enabled = False
Me![Dir Current Date].Enabled = False
Else
If (Me.[Text123] + Me.[Text125] + Me.[Text126]) >= 5000 Then
Me.[Director Approval].Enabled = True
Me.[Dir Signature].Enabled = True
Me![Dir Current Date].Enabled = True
End If
End If
End Sub
I tried an else since it just stays grayed out no matter what total I
have
in the box.
Do you see anything wrong with the statement? I quite puzzled here!
:
You would need to run this in the form's Current event and also in the
AfterUpdate event of any control that, if changed, would affect the
value
of
SumOfNRE.
If referring to the value of the textbox doesn't work, you may need to
put
the equation from the textbox into the If statement instead. It takes
a
few
seconds for the calculated controls to show a value and it may be that
the
code has passed that point already.
For example, if the equation in SumOfNRE is =txt1+txt2, then change
the
If
statement to:
If (Me.txt1 + Me.txt2) < 5000 Then
If the equation is long, you may want to assign its result to a
variable
then use the variable in the If statement to make things easier to
read.
--
Wayne Morgan
MS Access MVP
I am having trouble with the code to gray out fields if my total is
less
than
$5000. The graying out part works, but for some reason the number
doesn't.
I've tried it a dozen different ways. Also, would I place this in
On
current, On Open or what? The field is a calculated field and my
present
code is below. Thanks in advance!
If Me.SumofNRE < 5000 Then
Me.[Director Approval].Enabled = False
Me.[Dir Signature].Enabled = False
Me![Dir Current Date].Enabled = False
End If