Compile error: User-defined type not defined.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • suneelkp
    New Member
    • Mar 2013
    • 1

    Compile error: User-defined type not defined.

    Hi everyone,
    I am trying to use the code from internet to create and populate a tree view control. But in the first line itselef I am getting error in " Dim node As node".

    Compile error: User-defined type not defined.

    I already referenced Microsoft DAO3.6 Object library, Microsoft Activex Data Objects 2.8 library and Microsoft Office 12.0 library. But still I am getting the same error.

    Thanks in advance
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    Doy you have a Reference to the Microsoft Windows Common Controls X.X Object Library, of which the TreeView is a part of?

    Comment

    • redslayer
      New Member
      • Mar 2013
      • 2

      #3
      Dim node as node

      naming a variable as an object type isn't good practise - even if the compiler allows it; (such as Dim string as string).

      Comment

      • zmbd
        Recognized Expert Moderator Expert
        • Mar 2012
        • 5501

        #4
        RedSlayer:

        You need to explain that a tad more...
        Of course one defines (DIM) an object to a variable in VBA, for example:
        Code:
        DIM zDB as DAO.Database
        DIM zRS as DAO.Recordset
        These are both object types and if not defined either as early or late bind the database will not be available (now I only used the DAO object as one example... you can use connection strings and ADO and so many other methods to connect to a database).


        suneelkp:
        Please follow ADezii advise and reference the correct library as shown.

        Also, and this is what I suspect RedSlayer is trying to state:
        Do not use Reserved words or Key words as names for variables, fields, tables, user defined functions, etc... doing so is not only considered poor programing, it is often not allowed by the compilers and if it allowed by one compiler it is often not allowed by another; thus causing the end user no end of trouble.

        Comment

        • TheSmileyCoder
          Recognized Expert Moderator Top Contributor
          • Dec 2009
          • 2322

          #5
          @zmbd
          I believe you may have misunderstood Redslayers point. It is not a good idea to name a VARIABLE the same as an object type. To follow your example I would never do:
          Code:
          Dim Database as Dao.Database
          but would do the following if I truly felt that Database was the correct word to use:
          Code:
          Dim oDatabase as Dao.Database 'o short for object
          As for the original poster, you need to set a reference to the Microsoft Windows Common Control Library. This might not always be available from the list of references, but you can browse to it and find it in C:\Windows\syst em32
          and the library file is named MsComCtl.ocx

          Comment

          • zmbd
            Recognized Expert Moderator Expert
            • Mar 2012
            • 5501

            #6
            TheSmileyCoder:
            I don't think I misunderstood RS's intent at all:
            [Z]: (...) Also, and this is what I suspect RedSlayer is trying to state: Do not use Reserved words or Key words as names for variables, fields, tables (...)
            Thus, I think we are in agreement with RS's intent.

            However, with that said, it is that the wording used by RS is, at best, ambiguous - leading to the possible misinterpretati on if taken literally, as a novice programmer would be apt to do, that one should never use ANY variable name for an object. Instead of what you and I are stating that one should not use the reserved/keywords for variable names.

            :-) I may be nit-picking so to speak; however, it comes from 20 years of technical writing in chemistry labs where the wording must be exacting as the methods are often used by, or reviewed by, people with little or no science back ground. :)

            Comment

            Working...