Function Error Message

  • Thread starter Thread starter Dave the wave
  • Start date Start date
D

Dave the wave

I am experiencing bizarre Access97 behavior regarding having a function in
the "Control Source" of a text box control. The text box calculates a value
(using the function) from the values of 2 other controls (text boxes) on the
same form. The call to the function and the results are correct, but if I
try to make a change to the equation in any way I get an error message:

"The function you entered cannot be used in this expression.
You may have used DoEvents, LBound, UBound, Spc, or Tab function in
expression.
You may have used an SQL aggregate function, such as Count, in a design grid
or in a calculated control or field."
"OK" button only

Even if I edit the equation back to the original text I continue to get this
error message. I escape out, close the form, reopen and the function works
fine????

Form controls
[tbxTotalHours].controlSource==IIf(IsNull([RepackProductionStart]) Or
IsNull([RepackProductionStop]),"0.00",Total_Hours([RepackProductionStart],[RepackProductionStop]))

Form Module function:
Private Function Total_Hours(dblStart As Double, dblStop As Double) As
Double
If Not (IsNull(dblStart)) And Not (IsNull(dblStop)) Then
If dblStop < dblStart Then
dblStop = dblStop + 24
End If

Total_Hours = dblStop - dblStart
Else:
Total_Hours = 0
End If
End Function

I was considering simplifying the control source text to eliminate the IIf
and IsNull parts since the function is handling the data evaluation also.
New Control Source text
"=Total_Hours([RepackProductionStart],[RepackProductionStop])"

I get the above error message for the new control source text and have to
close form and reopen to get things to work.

I also need to expand the function to include 2 more text box controls. (A
single incident can cause more than one production stoppage.) I tried
modifying the function, and writing a new function "Multistop_Total_Hours".
Both resulted in the error message shown above???

Any pointers on what might be causing this problem would be greatly
appreciated!
 
For this and other reasons, I tend to avoid putting code
in the control source of controls. Rather calculate the
result elsewhere (button, form event, whatever) and paste
the result.
-----Original Message-----
I am experiencing bizarre Access97 behavior regarding having a function in
the "Control Source" of a text box control. The text box calculates a value
(using the function) from the values of 2 other controls (text boxes) on the
same form. The call to the function and the results are correct, but if I
try to make a change to the equation in any way I get an error message:

"The function you entered cannot be used in this expression.
You may have used DoEvents, LBound, UBound, Spc, or Tab function in
expression.
You may have used an SQL aggregate function, such as Count, in a design grid
or in a calculated control or field."
"OK" button only

Even if I edit the equation back to the original text I continue to get this
error message. I escape out, close the form, reopen and the function works
fine????

Form controls
[tbxTotalHours].controlSource==IIf(IsNull ([RepackProductionStart]) Or
IsNull([RepackProductionStop]),"0.00",Total_Hours ([RepackProductionStart],[RepackProductionStop]))

Form Module function:
Private Function Total_Hours(dblStart As Double, dblStop As Double) As
Double
If Not (IsNull(dblStart)) And Not (IsNull(dblStop)) Then
If dblStop < dblStart Then
dblStop = dblStop + 24
End If

Total_Hours = dblStop - dblStart
Else:
Total_Hours = 0
End If
End Function

I was considering simplifying the control source text to eliminate the IIf
and IsNull parts since the function is handling the data evaluation also.
New Control Source text
"=Total_Hours([RepackProductionStart], [RepackProductionStop])"

I get the above error message for the new control source text and have to
close form and reopen to get things to work.

I also need to expand the function to include 2 more text box controls. (A
single incident can cause more than one production stoppage.) I tried
modifying the function, and writing a new
function "Multistop_Total_Hours".
 
Back
Top