Dale,
Thanks for the reply, but I still cannot get the code to work.
I used the example you sent =fnMax([P1], [P2], [P3], [P4], [P5], [P6],
[P7]) in the record source of the Totals Textbox
and the value shown is #Name?
the code is shown below as per my module called fnMax
Each data field is named P1 P2 etc.
Have you any ideas.
Regards
John
Public Function fnMax(ParamArray SomeValues() As Variant) As Variant
Dim intLoop As Integer
Dim myMax As Variant
For intLoop = LBound(SomeValues) To UBound(SomeValues)
If IsNull(SomeValues(intLoop)) Then
'do nothing
ElseIf SomeValue(intLoop) = "" Then
'do nothing
ElseIf IsEmpty(myMax) Or SomeValues(intLoop) > myMax Then
myMax = SomeValues(intLoop)
End If
Next
fnMax = myMax
End Function
Dale Fye said:
John,
Duh! My fault, I was writing this directly into the newsgroup, rather
than cutting it from a code module.
When you pass the function a parameter array, it has to be the last
variable in the function declaration(Access doesn't know where the array
ends and the next variable begins). Since I took out the IgnoreZLS code
anyway, you really didn't even need that variable in the declaration.
Change the function declaration to:
Public Function fnMax(ParamArray SomeValues() As Variant) As Variant
Dale
Dale
I copied the code below as is, into a new module and there are errors
apparent.
I am being told of a
"compile error: ) expected"
at the end of
SomeValues() As Variant,
Public Function fnMax(ParamArray SomeValues() As Variant, Optional
IgnoreZLS
as boolean = true) As Variant
Dim intLoop As Integer
Dim myMax As Variant
For intLoop = LBound(SomeValues) To UBound(SomeValues)
If IsNull(SomeValues(intLoop)) Then
'do nothing
elseif SomeValue(intLoop) = "" then
'do nothing
ElseIf IsEmpty(myMax) Or SomeValues(intLoop) > myMax Then
myMax = SomeValues(intLoop)
End If
Next
fnMax = myMax
End Function
I am using access 2007, would this matter?
Regards
John
Dale,
Would I just copy the code into a new module?
Regards
John
Hi,
I have 20 fields on a form which shows the current progress of a
project, text boxes are named P1 through P20 to show stages.
I would like to have an unbound textbox which would show a total
percent completed.
Only the numbers are shown in the textboxes. P1 etc is the textbox
name.
i.e. P1=0 P2=10 P3=20 P4=25 P5=30 P6="" P7=""
etc Total = 30%
Obviously there will always be a number of textboxes with no data
entered (15 in the example above)
The form is based on a query.
Would I need to set the parameters in the Query? or How would I code
this on the form?
Regards
John