Results 1 to 5 of 5
  1. #1
    martingaleh is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2015
    Posts
    22

    Types, classes and collections

    I have a parent with children. The parent has a name and a list of children. each child has a name and an age. I wanted to make something liek



    Code:
    type child
     name as string
     age as long
    end type
    but everyone and their mother says to use classes instead because of binding issues

    so in a class module named "child" i made:
    Code:
    public name as string
    pubic age as long
    and then I made:

    Code:
    dim parent as collection
    set parent = new collection
    parent.add "larry", "name"
    
    dim childlist(0 to 2) as child
    set childlist(0) = new child
    set childlist(1) = new child
    parent.add childlist, "list"
    parent!list(0).name = "harry"
    Which fails utterly.

    Note: there may be syntax issues, but childlist(0).name works fine
    Is there some other syntax for a collection->array->class->public member?

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,716
    Why not step back and tell readers in simple, plain English what you are trying to accomplish?

  3. #3
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    Maybe you can create a parent class and include a collection of Child as a public field. You could include Name and Age in the Child class. Then, when you create a Parent, you can include its Childs. You could then create a collection of Parents in your form object's module or wherever.

    Here is some example code here that might give you some ideas. Couple things, if you decide to use Class_Initialize you may also want to consider Class_Terminate. And you need to scroll down to see where the error in the original post is.
    https://www.accessforums.net/modules...ses-54850.html

  4. #4
    martingaleh is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2015
    Posts
    22
    Yes, the main difference between the It's Me solution and the one I made is I didn't use a series of classes wrapping collections, I used an array instead. I guess this is the best practice because you can't address a collection->array->class->public member?
    in VBA
    Alas...

  5. #5
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    EDIT: I revisited your original post and I think the issue is that you are trying to use a complex data type as an element within an Array. So, use collections to hold other collections. I am saying this from memory, so you might want to see what is allowed in Arrays. I think the largest is a variant. However, there are different types of Variants. I think the distinction may be using a complex data type verses simple data types as an element within an Array.

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

Similar Threads

  1. Replies: 6
    Last Post: 08-31-2015, 09:50 AM
  2. Classes not taken
    By sdc1234 in forum Queries
    Replies: 1
    Last Post: 02-20-2014, 02:16 PM
  3. Budget and Collections(Actuals)
    By dref in forum Queries
    Replies: 20
    Last Post: 08-23-2012, 06:12 AM
  4. Replies: 7
    Last Post: 10-25-2011, 08:32 PM
  5. Budget and Collections(Actuals)
    By dref in forum Forms
    Replies: 0
    Last Post: 08-19-2010, 03:39 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