Results 1 to 11 of 11
  1. #1
    dgberry is offline Novice
    Windows 8 Access 2007
    Join Date
    Mar 2015
    Posts
    13

    Dynamic Variables

    I have a couple of tables that are linked in a parent-child relationship. I want to be able to update the parent and child information and It could go down several levels, like in a bill of materials.




    Can I create dynamic variables that will initialize as needed? I can use a "Level" variable as a counter to keep track of levels and increment and decriment it as it digs down and then back up.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Certainly. All variables are dynamic. They can be set and reset as needed in code. Common application of dynamic variable is the counter in a loop structure.
    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
    dgberry is offline Novice
    Windows 8 Access 2007
    Join Date
    Mar 2015
    Posts
    13
    This is more like part1, part2, part3, etc... Where the first part of the var name is fixed and then new variables are created by using a counter to concatenate the fixed part with the variable part.

    Maybe a dynamic array would work better.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    No, variable names cannot be dynamic in VBA. Yes, an array may be appropriate.
    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.

  5. #5
    dgberry is offline Novice
    Windows 8 Access 2007
    Join Date
    Mar 2015
    Posts
    13
    Dang. Might be an option for future releases.

    Thank you.

    I might have to create a fixed number and then hope they do not go deeper than the number created.

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Don't hold your breath!
    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.

  7. #7
    Micron is offline Very Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    Quote Originally Posted by dgberry View Post
    This is more like part1, part2, part3, etc... Where the first part of the var name is fixed and then new variables are created by using a counter to concatenate the fixed part with the variable part.

    Maybe a dynamic array would work better.
    What if the array name was the fixed part and you used the Join and Split functions to build or deconstruct the elements for the variable part? You could also alter the element values in an array by referencing their position.

  8. #8
    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,870
    If you are dealing with bill of materials (hierarchy of structures)

    Sample database and description here.

  9. #9
    CJ_London is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,932
    if you don't know how many levels of sub assemblies etc, you need to learn about binary trees and alternatives such as nested sets.

    However these can be difficult to implement in sql code because they require a recursive action not available in access (or many other db's type). However you can have recursive code in vba which you can use to either build a bespoke sql query or to populate a recordset

  10. #10
    dgberry is offline Novice
    Windows 8 Access 2007
    Join Date
    Mar 2015
    Posts
    13
    I already have the structure setup for the database. I am in the proccess of doing the cost and qty rollups using VBA. I've done recursive in a C++ class, looks like I get to learn in VBA.

  11. #11
    dgberry is offline Novice
    Windows 8 Access 2007
    Join Date
    Mar 2015
    Posts
    13
    Binary trees? I've looked for that in Access help, but it wasn't too helpful.

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

Similar Threads

  1. Replies: 5
    Last Post: 12-22-2012, 01:36 PM
  2. Dynamic Form, Dynamic labels/ captions?
    By JFo in forum Programming
    Replies: 15
    Last Post: 10-12-2011, 08:33 PM
  3. VBA variables in SQL
    By compooper in forum Programming
    Replies: 3
    Last Post: 07-06-2011, 11:04 AM
  4. VBA in variables
    By smikkelsen in forum Access
    Replies: 3
    Last Post: 11-12-2010, 03:14 PM
  5. sql in vb variables
    By emilylu3 in forum Programming
    Replies: 3
    Last Post: 03-04-2006, 01:26 PM

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