Results 1 to 5 of 5
  1. #1
    Eef is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Oct 2014
    Posts
    11

    Lightbulb using dynamic label/variable name

    Hi, as a beginner in VBA and Access I created a table with 6 fields named:
    Lid_Name_01
    Lid_Name_02
    .......
    Lid_Name_06

    I also created a new function in a module to process the table.


    I wrote code to process the 6 fields indivually but it must be possible to do this in a loop.
    My statements lookes like:
    In1![Lid_Name_01] = <new value>
    In1![Lid_Name_02] = <new value>
    ...............
    In1![Lid_Name_06] = <new value>

    Now I want to create a loop where the last digit of the fieldname (1-6) must be substituted by a variable. Like:
    For iCount = 1 to 6
    In1![Lid_Name_0<value of iCount>] = <new value>
    Next iCount

    I tried several things, but without success so far.

    Who can help me solve this problem?

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,549
    Code:
    for iCount = 1 to 6
    
     In1.fields("Lid_Name_0" & iCount).value = NewValue
    
    next

  3. #3
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Just be aware that this is not a normalized table structure. This type of table structure is called "Committing Spreadsheet".
    Currently, your structure is wide and short (like Excel). A normalized table will be narrow and tall.


    A normalized structure would look like
    Lid_Name
    Lid_Sequence



    In a normalized table, you would have records like:
    In1![Lid_Name] = "Big"
    In1![Lid_Sequence] = 1

    In1![Lid_Name] = "Medium"
    In1![Lid_Sequence] = 2

    In1![Lid_Name] = "Small"
    In1![Lid_Sequence] = 3


    Good luck with your project........

  4. #4
    Eef is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Oct 2014
    Posts
    11

    Smile Thanks

    Thanks, I was looking for this solution. It works!

    Eef
    Quote Originally Posted by ranman256 View Post
    Code:
    for iCount = 1 to 6
    
     In1.fields("Lid_Name_0" & iCount).value = NewValue
    
    next

  5. #5
    Eef is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Oct 2014
    Posts
    11
    Hi, I know what you mean. This is not the ultimate solution, but it is the way it is now.
    After 40years of ICT (System Software and Databases (IDMS, DB2) I know about normalization.

    Eef
    It's not my fault, it's the default........!

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

Similar Threads

  1. Replies: 1
    Last Post: 04-25-2014, 11:41 AM
  2. Dynamic Label in report
    By lugnutmonkey in forum Reports
    Replies: 1
    Last Post: 02-27-2013, 03:19 PM
  3. Dynamic/Variable Image File on Report
    By JoeM in forum Reports
    Replies: 5
    Last Post: 02-26-2013, 06:59 AM
  4. Dynamic Form, Dynamic labels/ captions?
    By JFo in forum Programming
    Replies: 15
    Last Post: 10-12-2011, 08:33 PM
  5. Replies: 0
    Last Post: 08-10-2011, 11:59 AM

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