Results 1 to 5 of 5
  1. #1
    Newby is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Nov 2012
    Posts
    60

    Looping thru fields.

    I am currently calculating a rolling 12 month average and I am set up a loop to collect the necessary data. For example for Aug 2012, I want the the sum of the first 8 months of 2012 and the last four months of 2011. So if January is the 5th field, I want ot loop thru the current record summing the next field 8 times (field 5-13). Then I want the last 4 months of last year's record. Field 9(13-4)-13.



    I used MoveNext to go to the next record. Is there a similar reference to next or previoius fields?

    Thank you in advance

    John

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Yes. http://msdn.microsoft.com/en-us/libr...(v=vs.85).aspx

    EDIT: Sorry, misread original post. See next post.

    However, Fields Collection using index might only be relevant to recordset, not referencing form elements. Are you using RecordsetClone method?
    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
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    So if January is the 5th field, I want ot loop thru the current record summing the next field 8 times (field 5-13). Then I want the last 4 months of last year's record. Field 9(13-4)-13.
    You totally lost me... It sounds like you do not have a normalized structure.

    In any case, look in Help for "Fields Collection". You can refer to a field by its ordinal number ie Fields(0),Fields(1), ...
    Remember that the index is zero based, so the 5th field would be Fields(4). You can set up a FOR..NEXT loop to sum fields in a row.

  4. #4
    Newby is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Nov 2012
    Posts
    60

    Thanks. Stupid question, how do i mark a thread as solved?

    Quote Originally Posted by ssanfu View Post
    You totally lost me... It sounds like you do not have a normalized structure.

    In any case, look in Help for "Fields Collection". You can refer to a field by its ordinal number ie Fields(0),Fields(1), ...
    Remember that the index is zero based, so the 5th field would be Fields(4). You can set up a FOR..NEXT loop to sum fields in a row.
    Stupid question, how do i mark a thread as solved?

  5. #5
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Look for "Thread Tools" at the top of the page. (right hand side of 2nd green green bar)

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

Similar Threads

  1. Looping
    By ddrew in forum Forms
    Replies: 8
    Last Post: 10-08-2012, 01:48 AM
  2. Looping query
    By jaykappy in forum Queries
    Replies: 13
    Last Post: 02-24-2012, 03:05 PM
  3. Looping Search
    By srmezick in forum Forms
    Replies: 5
    Last Post: 11-04-2011, 11:13 AM
  4. Looping through a tbl to find a certain value
    By cwf in forum Programming
    Replies: 1
    Last Post: 05-17-2010, 04:02 PM
  5. Looping syntax
    By fadiaccess in forum Access
    Replies: 1
    Last Post: 10-23-2009, 02:57 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