Results 1 to 3 of 3
  1. #1
    Rawb is offline Expert
    Windows XP Access 2000
    Join Date
    Dec 2009
    Location
    Somewhere
    Posts
    875

    Building my Own Collection(s) - Attempt #2!

    Graaaaahhhhh! Why can't I figure this out??!?



    I'm trying to make a user-defined Collection to hold instances of a user-defined Class Object. But I can't figure out how to do it because all of the Tutorials I've been able to find on the subject say that you need to define the Class and the Collection in different Code Modules but don't show you where one Module ends and another starts. Most of them also make some incredibly frustrating assumptions, like they're trying to explain the concept to someone that already knows what they're talking about! >:(

    Anyway, first issue: My custom Class. I've got the basic code figured out (I think) with the variables that the Object will hold and some Get/Let Properties:

    Module: tSortItem
    Code:
    Option Compare Database
    Option Explicit
    
    Public tIndex As Long
    Public tLastUpdated As Date
    Public tName As String
    
    ' Index is read/writeable
    Property Get Index() As Long
      Index = tIndex
    End Property
    
    Property Let Index(Value As Long)
      tIndex = Value
    End Property
    
    
    ' LastUpdated is read/writeable
    Property Get LastUpdated() As Date
      LaqstUpdated = tLastUpdated
    End Property
    
    Property Let LastUpdated(Value As Date)
      tLastUpdated = Value
    End Property
    
    
    ' Name is read/writeable
    Property Get Name() As String
      Name = tName
    End Property
    
    Property Let Name(Value As String)
      tName = Value
    End Property
    Is there anything else I need to add to this code?

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,948
    I never done UDF collections so will be a learning experience.

    You have the above code in a Class Module? Then you declare and use the object in some general or object (form/report) code module?

    I am trying to do just that. I put your code in a Class module called MyClass. I created a procedure in a general module:
    Sub testMyClass()
    tName="test1"
    Dim MyObj As New MyClass
    Debug.Print MyObj.Name
    End Sub

    VBA is not finding the tName variable declared in the Class module. I moved those declarations to the general module header and the Sub works.


    Typo in 'LaqstUpdated'.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    Rawb is offline Expert
    Windows XP Access 2000
    Join Date
    Dec 2009
    Location
    Somewhere
    Posts
    875
    OK, using your example as a Template I've made some more modifications to my Class (saved in a Class Module named "tSortItem")

    I've fleshed a few things out, including adding/changing variables around to hold the information that I will be using. I've also made LastUpdated (corrected my typo btw, thanks for that ) read-only - It now can't be changed directly and updates automatically when Index is changed.

    Class Module tSortItem
    Code:
    Option Compare Database
    Option Explicit
    
    Public Enum tSortType
      tSortAsc = 1
      tSortDesc = 2
      [_First] = 1
      [_Last] = 2
    End Enum
    
    Private tIndex As Long
    Private tField As String
    Private tLastUpdated As Date
    Private tTable As String
    Private tSort As tSortType
    
    ' Index is read/writeable
    Property Get Index() As Long
      Index = tIndex
    End Property
    
    Property Let Index(Value As Long)
      tIndex = Value
      tLastUpdated = Now()
    End Property
    
    
    ' Field is read/writeable
    Property Get Field() As String
      Field = tField
    End Property
    
    Property Let Field(Value As String)
      tField = Value
    End Property
    
    
    ' LastUpdated is read-only
    Property Get LastUpdated() As Date
      LastUpdated = tLastUpdated
    End Property
    
    
    ' Sort is read/writeable
    Property Get SortMethod() As tSortType
      SortMethod = tSort
    End Property
    
    Property Let SortMethod(Value As tSortType)
      tSort = Value
    End Property
    
    
    ' Table is read/writeable
    Property Get Table() As String
      Table = tTable
    End Property
    
    Property Let Table(Value As String)
      tTable = Value
    End Property
    Now, I just need to create a Collection Class and tie the two together!

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Building my own Collection(s)
    By Rawb in forum Programming
    Replies: 2
    Last Post: 12-14-2012, 01:01 PM
  2. Replies: 3
    Last Post: 11-16-2012, 10:15 AM
  3. Replies: 7
    Last Post: 08-10-2012, 03:09 PM
  4. Failed attempt at concetenation
    By snowboarder234 in forum Queries
    Replies: 2
    Last Post: 07-12-2012, 09:02 AM
  5. First Timer attempt at Project List
    By SHogan in forum Reports
    Replies: 3
    Last Post: 02-06-2012, 10:33 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums