Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find the return type in VBA

Tags:

vba

ms-access

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.

like image 586
Mahyar Avatar asked May 07 '12 12:05

Mahyar


1 Answers

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.

like image 96
HansUp Avatar answered Nov 15 '22 16:11

HansUp