How to find return type in VBA

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

+7
source share
1 answer

If this is a built-in function, see the Access help topic.

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

If you cannot do this, use the TypeName() function to specify the data type returned by YourFunction() .

 Debug.Print TypeName(YourFunction()) 

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

Heinzi suggested VarType() instead of TypeName() . Usually I usually reach TypeName() simply because it is faster for me and I rarely worry about its limitations. However, I agree with Heinzi; VarType() better.

JP. suggested two other useful suggestions. First, you can create a simple procedure that declares a Variant variable and assigns the value of the returned function to the variable. Then add a temporary breakpoint (with F9 ) in the first line of Debug.Print , run the procedure, use F8 to move through it line by line and track the value of the variable in the Locals window. (Open this window from the main menu of the VB editor. View → Locals Window)

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

And secondly, for built-in functions that have a return type, you can use Intellisense to view the return type when entering a function name and / or parameters.

+12
source

All Articles