|
|
TypeOf The TypeOf statement can be used to check if an object reference is a specified type of object. For example, we can use TypeOf to see if a Control is a Textbox, or a Form, or a Class Object. In VBA, the Help for TypeOf can be found under the If/Then help file, and is sparing in it's description.
[edit] Basic SyntaxThe basic syntax is as follows:
Substitute MyObject with your object reference, and ObjectType with the type of object you would like to test for. For example:
The "TypeOf X Is Y" clause can be used in many cases where a boolean variable can be returned. For Example:
You can negate the return through one of the following two syntaxes:
[edit] Derived Objects and TypeOfTypeOf can be used to compare objects to a derived object. For example, a Textbox control might be checked against an Access.TextBox, an Access.Control and an Object, all of which return True:
This would yield the following results:
[edit] Custom (Class) ObjectsTypeOf can be used on any object. For example, if we have a class clsMyClass, and we want to see if an object is an instance of MyClass, we can use the following:
[edit] RestrictionsTypeOf cannot be used to determine if a variable is a user defined type, nor can it be used to see if a variable is of a standard type (Integer, String, Boolean, etc).
|
| This page was last modified 17:04, 11 February 2012. This page has been accessed 289 times. Disclaimers |