Hi Kevin,
It sounds as if you were looking for something like this:
Function BrowseFolder() As String
...
On Error Goto ErrExit
...
BrowseFolder = blah
GoTo NormalExit
ErrExit:
BrowseFolder = ""
NormalExit:
'Tidy up
...
End Function
which will return an empty string if an error occurs and the desired
value otherwise.
As for your question: the return value is always the last value
successfully assigned to the name of the function (assuming the error is
handled and a value is actually returned to the calling code).
If there hasn't been such an assignment, it will (I think) be the
default value of a variable of the same type as the function. This means
that the return value may vary depending on whereabouts in the code the
error occurred (and, for all I know, on just what error occurred). So
it's safest, and usually makes for better programming style, always to
assign explicit return values.
forgotten to put Option Explicit...
Thanks, John. It was my first non-form class module, and
indeed I had forgotten the Option Explicit declaration.
The problem, however, was that the function, prior to
returning its value, was being set to blank by the error-
handling code:
ErrExit:
BrowseFolder = ""
Exit Function
Which raises the question: if an error occurs in the
function, what value is returned for string, boolean, and
numeric functions? If it returns a blank string for a
string function, the code that caused the problem was
unneccessary.
Thanks for your help.
John Nurick [Microsoft Access MVP]
Please respond in the newgroup and not by email.