How to find the return type in VBA

ms-access, vba

Solution

If it is a built-in function, look at the Access help topic.

If it is a user-defined function, examine its definition.

If you can do neither, use the `TypeName()` function to tell you the data type returned by `YourFunction()`.

Debug.Print TypeName(YourFunction())

If `YourFunction()` returns a variant, `TypeName()` will tell you the variant subtype.

Heinzi suggested `VarType()` instead of `TypeName()`. I habitually reach for `TypeName()` first simply because it's quicker for me, and I'm seldom concerned with its limitations. However I agree with Heinzi; `VarType()` is better.

JP. offered two other useful suggestions. First, you can create a simple procedure which declares a Variant variable and assign your function's return value to the variable. Then add a temporary break point (with F9) on the first `Debug.Print` line, run the procedure, use F8 to move through it line by line, and monitor the variable's value in the Locals Window. (Open that window from the VB editor's main menu. View -> Locals Window)

Public Sub examine_YourFunction()
    Dim varFoo As Variant
    Debug.Print "start"
    varFoo = YourFunction()
    Debug.Print varFoo
End Sub

And second, for built-in functions that have a return type, you can take advantage of Intellisense to see the return type as you are typing the function name and/or the parameters.

Problem

I have a MS Access application and have problem to find a return type of function. Is there a way to find return type of object? I have type mismatch error.

Original source