J
JString
I've run into a strange problem that I've never seen before... I wrote a
function in VBA and plugged it into a query, and it works fine for the most
part but on a few records it returns a value which it was not designed to do.
The function is supposed to loop through the items passed to it and return
the smallest value. Should be pretty straightforward.
The function is:
Public Function Smallest(ParamArray items() As Variant) As Variant
On Error GoTo Err_Handler
upper = UBound(items)
varReturn = items(0)
For i = 1 To upper
If varReturn > items(i) Then varReturn = items(i)
Next i
Smallest = varReturn
Exit Function
Err_Handler:
Smallest = -1
End Function
And the query def:
SELECT [Query2].Qty, [Query1].Qty, Smallest([Query2]![Qty],[Query1]![Qty])
AS Expr2
FROM [Query2] INNER JOIN [Query1] ON [Query2].typeID = [Query1].typeID;
Like I said this actually works for most of the records, but for some odd
reason I will get a few records for which the function returned the larger
value.
Can anyone tell me what I'm doing wrong?
function in VBA and plugged it into a query, and it works fine for the most
part but on a few records it returns a value which it was not designed to do.
The function is supposed to loop through the items passed to it and return
the smallest value. Should be pretty straightforward.
The function is:
Public Function Smallest(ParamArray items() As Variant) As Variant
On Error GoTo Err_Handler
upper = UBound(items)
varReturn = items(0)
For i = 1 To upper
If varReturn > items(i) Then varReturn = items(i)
Next i
Smallest = varReturn
Exit Function
Err_Handler:
Smallest = -1
End Function
And the query def:
SELECT [Query2].Qty, [Query1].Qty, Smallest([Query2]![Qty],[Query1]![Qty])
AS Expr2
FROM [Query2] INNER JOIN [Query1] ON [Query2].typeID = [Query1].typeID;
Like I said this actually works for most of the records, but for some odd
reason I will get a few records for which the function returned the larger
value.
Can anyone tell me what I'm doing wrong?