Why Does The Typename Of A Form Return The Form’s Name, And Not Its Type?

You create a routine that uses the Typename() function to find out thetype of an object, and based on that type, performs certain actions. However,when used in a Form object, the value returned by Typename() is not thegeneric object class “Form.” It is, instead, the specific objectclass “Form1.”Try running this sample:

 Private Sub Form_Load()	Dim frm as Form	set frm = Me	Debug.Print TypeName(frm), frm.Name 	'<< prints: Form1 Form1End Sub

You expect TypeName(frm) to resolve to Form instead of Form1 but itdoesn't. That is because the type of the object, in this case, is the formclass itself, Form1. That you assigned it to a Form object does nothingexcept to prevent you from calling any of the Form1 objects methods andproperties directly in code. Similarly, a control never gives a type nameof "Control." Instead, the type name is always something like"CommandButton" or "PictureBox."Interestingly, while the TypeName function returns the most specificname, the If-TypeOf syntax will match either the generic class type orthe specific object class. In other words, both of these If statementswould return True:

 Set frm = MeIf TypeOf frm Is Form1 Then Debug.Print "Form1"If TypeOf frm Is Form Then Debug.Print "Form" '<< both stmts are true
Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

The Latest

your company's audio

4 Areas of Your Company Where Your Audio Really Matters

Your company probably relies on audio more than you realize. Whether you’re creating a spoken text message to a colleague or giving a speech, you want your audio to shine. Otherwise, you could cause avoidable friction points and potentially hurt your brand reputation. For example, let’s say you create a

chrome os developer mode

How to Turn on Chrome OS Developer Mode

Google’s Chrome OS is a popular operating system that is widely used on Chromebooks and other devices. While it is designed to be simple and user-friendly, there are times when users may want to access additional features and functionality. One way to do this is by turning on Chrome OS

homes in the real estate industry

Exploring the Latest Tech Trends Impacting the Real Estate Industry

The real estate industry is changing thanks to the newest technological advancements. These new developments — from blockchain and AI to virtual reality and 3D printing — are poised to change how we buy and sell homes. Real estate brokers, buyers, sellers, wholesale real estate professionals, fix and flippers, and beyond may