Results 1 to 5 of 5
  1. #1
    ohthesilhouettes is offline Novice
    Windows Vista Access 2007
    Join Date
    Jun 2011
    Posts
    7

    Help with adding rows (Complex!)

    Hi Everyone,

    I have a table that lists four columns (Treaty, Country, YearIn, YearOut)
    A country can join a treaty in one year and leave the treaty another year.

    Here is what the table looks like:

    Treaty Country YearIn YearOut
    Kyoto FRANCE 1990 1993
    Kyoto JAPAN 1990 1995
    Ocean CHINA 1980 1983
    Ocean FRANCE 1980 1983
    Ocean CANADA 1985 1987



    I need to combine the YearIn and the YearOut columns into rows of each year. This means adding new rows that repeat with the only difference is the year. The columns YearIn and YearOut serve as the boundary years but I need to automatically fill rows between the range

    Here is what I want it to look like.

    Treaty Country MemberYear

    Kyoto FRANCE 1990
    Kyoto FRANCE 1991
    Kyoto FRANCE 1992
    Kyoto FRANCE 1993
    Kyoto JAPAN 1990
    Kyoto JAPAN 1991
    Kyoto JAPAN 1992
    Kyoto JAPAN 1993
    Kyoto JAPAN 1994
    Kyoto JAPAN 1995
    Ocean CHINA 1980
    Ocean CHINA 1981
    Ocean CHINA 1982
    Ocean CHINA 1983
    Ocean FRANCE 1980
    Ocean FRANCE 1981
    Ocean FRANCE 1982
    Ocean FRANCE 1983
    Ocean CANADA 1985
    Ocean CANADA 1986
    Ocean CANADA 1987

    Is it possible to do this with some kind of count function and append query? Thanks for any help!

    -Michelle

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    One way would be to open a recordset on the first table, plus a second recordset on the target table. Within a loop of the first recordset, use the year values in a For/Next loop. Within that loop, use the AddNew method of the second recordset to add records to the table, using values from the first recordset plus the For/Next loop counter.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    ohthesilhouettes is offline Novice
    Windows Vista Access 2007
    Join Date
    Jun 2011
    Posts
    7
    Hi Paul,

    THank you so much for replying!! I am not familiar with using recordsets in Access. How should I go about it? Are there good tutorial places to learn about recordsets? Also could you help me on getting started with the For/Next loop counter?

    Thank you!

    -Michelle

  4. #4
    stmoong is offline Competent Performer
    Windows Vista Access 2007
    Join Date
    Sep 2011
    Location
    Singapore
    Posts
    108
    Here is a link from MSDN for you to learn how to use DAO Recordset.

    http://msdn.microsoft.com/en-us/libr...ffice.12).aspx

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    How are you coming along Michelle?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 2
    Last Post: 08-28-2011, 06:06 AM
  2. Complex IIF Statement
    By ksamaniego in forum Queries
    Replies: 3
    Last Post: 08-11-2011, 09:09 AM
  3. Complex Criteria
    By Kapelluschsa in forum Queries
    Replies: 7
    Last Post: 05-23-2011, 03:45 PM
  4. Complex Joins??
    By objNoob in forum Queries
    Replies: 0
    Last Post: 03-16-2010, 02:42 PM
  5. Adding rows on cross-tab query report
    By KahluaFawn in forum Reports
    Replies: 2
    Last Post: 02-18-2009, 10:09 AM

Tags for this Thread

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