I don't see anywhere in the function that you're assigning
a value to the function itself. This is how VB functions
return values, by assigning a value to the function name.
Without this, the function returns no value. (This may be
the major reason this isn't working.)
Just before the "End Function", say "fGetCost = Cost".
This will cause the function to return a value.
Another point (which may be something of a personal preference): You're changing the value of one of your
input params. In the final "Else" of each of your "If"'s,
you say "iDuration = 0". Since argument passing is by
Reference in VB by default, this will actually change the
value of iDuration back in any routine that calls this one.
It really shouldn't have any effect here, but it's rather
dangerous, I think. I recommend passing arguments to
functions by Value, i.e.,
Code:
Function fGetCost(ByVal iDate As Date, ByVal iTime As Date, ByVal iDuration As Integer) As Double
This way if you accidentally make a change to one of your
params in a function, you're only changing a local copy
and the calling routine's values aren't affected.
And one last thing. In one of your earlier posts, you said:
"I tried putting in fGetCost([Date],[Time],[Duration]) in a field, but that only updated one record, not all."
Can you explain what you meant by "you tried putting it in
a field"?