Results 1 to 6 of 6

Thread: Determing Control Type

  1. #1
    Yash_Kumar
    Guest

    Determing Control Type

    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?

  2. #2
    Fanatic Member skald2k's Avatar
    Join Date
    Feb 2002
    Location
    Sydney, Australia
    Posts
    535
    use the function: typeOf(object)
    - If at first you dont succeed, then give up, cause you will never will!

  3. #3
    PowerPoster beachbum's Avatar
    Join Date
    Jul 2001
    Location
    Wollongong, NSW, Australia
    Posts
    2,274
    hi
    You can use either of these
    VB Code:
    1. Private Sub Command1_Click()
    2.     Debug.Print TypeName(Command1)
    3.     If TypeOf Command1 Is CommandButton Then Debug.Print "or this"
    4. End Sub
    Stuart Laidlaw
    Brightspark Financial Software
    http://www.gstsmartbook.com

  4. #4
    Fanatic Member skald2k's Avatar
    Join Date
    Feb 2002
    Location
    Sydney, Australia
    Posts
    535
    What is the difference between typeOf and Typename?
    - If at first you dont succeed, then give up, cause you will never will!

  5. #5
    PowerPoster beachbum's Avatar
    Join Date
    Jul 2001
    Location
    Wollongong, NSW, Australia
    Posts
    2,274
    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.
    Stuart Laidlaw
    Brightspark Financial Software
    http://www.gstsmartbook.com

  6. #6
    Fanatic Member skald2k's Avatar
    Join Date
    Feb 2002
    Location
    Sydney, Australia
    Posts
    535
    excellent! thnx.
    - If at first you dont succeed, then give up, cause you will never will!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width