I have an object that has been referenced to a certain control on a form. That control could either be a Label, Command Button, Frame, Form or Picture. COuld someone tell me how to know what type of control the object is referenced to?
Printable View
I have an object that has been referenced to a certain control on a form. That control could either be a Label, Command Button, Frame, Form or Picture. COuld someone tell me how to know what type of control the object is referenced to?
use the function: typeOf(object)
hi
You can use either of these
VB Code:
Private Sub Command1_Click() Debug.Print TypeName(Command1) If TypeOf Command1 Is CommandButton Then Debug.Print "or this" End Sub
What is the difference between typeOf and Typename?
TypeOf can only be used in an If Then statement
eg If TypeOf object Is objecttype Then
whereas Typename is a function that returns the actual name and so can be used in If Thens, select case or just as a string variable.
excellent! thnx.