M
Marty L
I want to be able to select the max from a set of columns. I don't want to
use IIf.
I have written a user defined function to find the maximum from a list of
values:
----------------------------------------------------------------------------
------
Public Function MaxInArray(varArray As Variant) As Variant
Dim varItem As Variant
Dim varMax As Variant
Dim intI As Integer
If IsArray(varArray) Then
If UBound(varArray) = -1 Then
MaxInArray = Null
Else
varMax = varArray(UBound(varArray))
For intI = LBound(varArray) To UBound(varArray)
varItem = varArray(intI)
If varItem > varMax Then
varMax = varItem
End If
Next intI
MaxInArray = varMax
End If
Else
MaxInArray = Null
End If
End Function
----------------------------------------------------------------------------
-----------
this works if I call it from a sub routine:
x = MaxInArray(array(1,2))
for example, but I want to be able to call it from a querydef:
where I have a field defined as the following expression:
Expr1: MaxInArray(Array([table1.field1],[table1.field2]))
When I try this I geta popup "Data type mismatch in criteria expression"
I know this is happening prior to the function being called because I have a
breakpoint in the function
Basic question - how do you build a function that you can use in a querydef
with multiple (1,2 or more) arguments? How do you pass the arguments?
Thanks, Marty
use IIf.
I have written a user defined function to find the maximum from a list of
values:
----------------------------------------------------------------------------
------
Public Function MaxInArray(varArray As Variant) As Variant
Dim varItem As Variant
Dim varMax As Variant
Dim intI As Integer
If IsArray(varArray) Then
If UBound(varArray) = -1 Then
MaxInArray = Null
Else
varMax = varArray(UBound(varArray))
For intI = LBound(varArray) To UBound(varArray)
varItem = varArray(intI)
If varItem > varMax Then
varMax = varItem
End If
Next intI
MaxInArray = varMax
End If
Else
MaxInArray = Null
End If
End Function
----------------------------------------------------------------------------
-----------
this works if I call it from a sub routine:
x = MaxInArray(array(1,2))
for example, but I want to be able to call it from a querydef:
where I have a field defined as the following expression:
Expr1: MaxInArray(Array([table1.field1],[table1.field2]))
When I try this I geta popup "Data type mismatch in criteria expression"
I know this is happening prior to the function being called because I have a
breakpoint in the function
Basic question - how do you build a function that you can use in a querydef
with multiple (1,2 or more) arguments? How do you pass the arguments?
Thanks, Marty