Results 1 to 11 of 11
  1. #1
    shod90 is offline Competent Performer
    Windows 8 Access 2016
    Join Date
    Jan 2016
    Posts
    134

    How to Loop through table fields with different way.

    Dear Gents,
    Um trying to loop through field names in my table and then insert each name on a button caption in my form , Something like the below example

    Field Names:

    ID
    ItemDesc

    Table records:
    1
    Item 1
    2


    Item 2
    3
    Item 3

    i need to make this like the below picture .
    Click image for larger version. 

Name:	Untitled-1.png 
Views:	27 
Size:	12.4 KB 
ID:	34498

  2. #2
    Minty is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,001
    What have you tried ? What are the command controls called, are they named in a sensible fashion to allow you to loop around them ?
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  3. #3
    shod90 is offline Competent Performer
    Windows 8 Access 2016
    Join Date
    Jan 2016
    Posts
    134
    Actually i don't know from where how to start ? i only created the table with the above fields and created a btn control then copy paste until they became 12 btn . Their names command0 , command1 , command2 .. etc.

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,716
    You may get some ideas from this post (from ChrisO post) but it deals with advanced concepts.
    If you look at the "Similar threads" at the bottom of the pages in this forum, you could review such posts for related info.

    I think google may be your best resource to find examples and articles for table and database design, form design and modules.

    Good luck.
    Last edited by orange; 06-20-2018 at 12:19 PM.

  5. #5
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,388
    Have a look at this:

    The form_load event will copy the captions from the table to the buttons.
    The captions are not permanent, so must be done via the form_load.

  6. #6
    shod90 is offline Competent Performer
    Windows 8 Access 2016
    Join Date
    Jan 2016
    Posts
    134
    Works like charm thanks buddy , But i wonder if i added another record in table tblNames how can i automatically add a new button with the new caption i've added in the table ? Is it possible ? . even if the form must be closed then opened again ?

  7. #7
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,388
    Much easier would be to have invisible buttons already existing on the form and make them visible with the form_load event if needed.

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,815
    Design modification in a deployed db should be rare. Programmatically modifying design is possible but not advised. Why do you need a button for each record as opposed to combo or list box or just listing records in form?
    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.

  9. #9
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,716
    shod90,

    If you need a setup to handle a changing number of "records", then some technique to identify the number of records, modify the form (some event) to add the requisite number of text boxes and populate with data from the record(s) as necessary.

    The sample from ChrisO shown in post #4 shows some of the techniques involved. Other databases by ChrisO with class modules
    may b available online.

    If you have a fixed number of records, you can set up the textboxes in design mode with proper naming, then use form load event to assign some values to textbox properties as Davegri has demonstrated. However, adding or subtracting records will force a form design change.

  10. #10
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,388
    OK, this version has 15 invisible buttons that become visible as the captions from tblNames are added, up to 15.
    I added a SortOrder field to tblNames that will allow you to control the position of each caption in the button grid.

  11. #11
    shod90 is offline Competent Performer
    Windows 8 Access 2016
    Join Date
    Jan 2016
    Posts
    134
    It works , Super .. Thank you

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

Similar Threads

  1. Replies: 4
    Last Post: 07-18-2016, 12:59 PM
  2. loop recordset and update fields
    By gammaman in forum Programming
    Replies: 9
    Last Post: 06-30-2016, 04:20 AM
  3. Replies: 27
    Last Post: 12-29-2015, 08:30 AM
  4. Replies: 3
    Last Post: 03-10-2013, 07:04 AM
  5. Replies: 1
    Last Post: 06-15-2012, 10:47 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