Use of "Public Type" in ACCESS 2003

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • peter1234
    New Member
    • Nov 2009
    • 11

    #1

    Use of "Public Type" in ACCESS 2003

    Could you please confirm if 'Public Type', as defined below, is possible with Access 2003. Symilar example found in a book for Access 2007.
    Code:
    Public Type TypeName
      Type as String
      Temp as Single
      Protect As Boolean
    End Type
    
    Public Function FnName()
      Dim Var1 as TypeName 
      Dim Var2 as TypeName
    
      ........
    End Function
    The error message inline 7 is:
    User-defined type not defined
    Last edited by NeoPa; Nov 29 '09, 05:20 PM. Reason: Please use the [CODE] tags provided.
  • orangeCat
    New Member
    • Dec 2007
    • 83

    #2
    I tried your example in Access 2003, by putting
    all of the code in an existing module. Access gave me the same error.

    Then I put just the
    Code:
    Public Type TypeName
     Type As String
     Temp As Single
     Protect As Boolean
     End Type
    in a separate module called ModuleType and saved it.

    Then ran this function

    Code:
      Public Function FnName()
    'can you use reference a Public Type in Acc 2003
      
       Dim Var1 As TypeName
       Dim Var2 As TypeName
       
       Var1.Type = "this is type"
       Var1.Protect = False
       Var1.Temp = 2
       
       Debug.Print "This is working  >" _
       & Var1.Type & "-" & Var1.Temp & "-" _
       & Var1.Protect
       
      End Function
    Result
    This is working >this is type-2-False

    Comment

    • ADezii
      Recognized Expert Expert
      • Apr 2006
      • 8834

      #3
      There is nothing wrong with the Syntax, but TypeName is the Name of a Built-In Function in Access, and Type is a Built-In Property of several Access Objects. I would bet that this is where the problem lies.

      Comment

      • NeoPa
        Recognized Expert Moderator MVP
        • Oct 2006
        • 32669

        #4
        Peter,

        I think that the point that orangeCat has highlighted is fundamental here. TypeDefs should be defined in standard code modules. Otherwise, they are much harder to reference and very much less generally useful.

        That said, ADezii's comments, while not identifying actual show-stoppers at this stage, are definitely worth taking note of. You are cetainly likely to hit problems if you use names that are already in use elsewhere, even if the problems can be got around with care. Much better to avoid this likelihood.

        Lastly, you have tried (by the look of it) to format your code in tags. They weren't the correct tags, but I appreciate the attempt. Perhaps the following will help you to use the correct ones in future. They are designed to be quite easy to use :
        You should know that we expect your code to be posted in [CODE] tags (See How to Ask a Question and indeed the instructions in the posting window itself).

        PS. Tags (generally) are done as matching pairs where the opening one is surrounded by [...] and the closing one by [/...]. A set of buttons is available for ease of use in the Standard Editor (Not the Basic Editor). The one for the [CODE] tags has a hash (#) on it. You can choose which editor to use in your Profile Options (Look near the bottom of the page). You must select the code in your post, and hit the button on the tool bar which looks like a hash (#). This will automatically format the post such that the [CODE] tags surround the code you're posting. This will display the code in a Code Box, quite differently from the standard formatting of a post.

        Comment

        • peter1234
          New Member
          • Nov 2009
          • 11

          #5
          Many thanks for all the comments, particularly to OrangeCat.

          The posted code was tested with different variable names. My objective at the moment is to establish the differences between Access 2007 and 2003. I would like to ensure the work I am doing in 2003 will work in the next version of Access.

          Comment

          • peter1234
            New Member
            • Nov 2009
            • 11

            #6
            Use of "Public Type" in ACCESS 2003

            You may want to know that the problem reported in ACCESS 2003 does not exist in ACCESS 2007.

            Comment

            Working...