+ Reply to Thread
Results 1 to 4 of 4

Adding new element to a collection propagatres added value to all entries

  1. #1
    Forum Contributor
    Join Date
    11-15-2012
    Location
    Buffalo, NY
    MS-Off Ver
    Office 365
    Posts
    286

    Adding new element to a collection propagatres added value to all entries

    I'm trying to populate a collection with PossibleAnswers to a Question. Every time I do this the values from the newly added entry get propagated to each entry in the collection (best way I can describe it - see code attachement).

    Here's the existing code - including the current debugging code surrounding the add!
    The function is a Method of a Question object.
    Please Login or Register  to view this content.
    All the Find and FindNext procedures do return the appropriate next value. However, the debug loop produces the following:
    Please Login or Register  to view this content.
    As you can see, something is being added, but it seems to be affecting every single entry.

    I know it's me (first rule of dumb) but can anybody help?

    Thanks,

    Tony

  2. #2
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Adding new element to a collection propagatres added value to all entries

    Your code is just adding new references to the localanswer object since I can't see anywhere in your code that changes it. So the code isn't affecting all items in the collection, you only have one object in the collection albeit multiple times, therefore changing the object appears to change all the items

  3. #3
    Forum Contributor
    Join Date
    11-15-2012
    Location
    Buffalo, NY
    MS-Off Ver
    Office 365
    Posts
    286

    Re: Adding new element to a collection propagatres added value to all entries

    Bingo, Kyle123

    I added 'just one line:

    Please Login or Register  to view this content.
    and it slipped properly back into shape!

    My conceptual error was in thinking that adding a new version of an instance adds a new instance. It simply adds another reference to the original instance - but with the updated values. When I checked back through my Version saves, the new clAnswer statement was there, and got dropped when I relocated the code. My bad! (No surprise, right ;-)

    Thanks again for your help. My head appreciates it, and so doe my study wall!

    Tony

  4. #4
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Adding new element to a collection propagatres added value to all entries

    Glad you got it sorted

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. When do you need to use a key argument when adding to a collection?
    By kestefon in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-18-2013, 12:21 AM
  2. Adding an element to all the formulas in the row
    By A_K in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 03-12-2013, 09:48 AM
  3. having a limit to how many entries can be added
    By jacklindsay in forum Excel General
    Replies: 1
    Last Post: 11-20-2007, 10:43 PM
  4. [SOLVED] Adding a collection to a wksht
    By CLamar in forum Excel General
    Replies: 1
    Last Post: 06-23-2006, 11:35 AM
  5. [SOLVED] Adding to a Collection
    By Cody in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-02-2005, 03:05 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1