Looping question

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • raneking22
    New Member
    • Dec 2006
    • 6

    #1

    Looping question

    I am automating a database for a client and I have run into a problem. I have researched it enough to know that I have to set up a loop. But, I can not find any code that will help me accomplish this. I am doing this in Access 2003.

    The problem is:

    I have a table with 25k records. Within these records I have around 100 unique manager values. I have built a query to group the managers together. Now what I want to do is to find a way to create 100 individual Excel 97-2003 files based on these manager groupings. So, for instance, 50 records containing value "SteveManag er" in the manager field would become an excel spreadsheet named SteveManager.xl s, and so on. This data is going to be overwritten every 3 months, so even creating 100 manual queries 1 time won't work because I would just have to redo it the next time since new managers are added/removed. Any help would be greatly appreciated!

    Jodie
  • MMcCarthy
    Recognized Expert MVP
    • Aug 2006
    • 14387

    #2
    Originally posted by raneking22
    I am automating a database for a client and I have run into a problem. I have researched it enough to know that I have to set up a loop. But, I can not find any code that will help me accomplish this. I am doing this in Access 2003.

    The problem is:

    I have a table with 25k records. Within these records I have around 100 unique manager values. I have built a query to group the managers together. Now what I want to do is to find a way to create 100 individual Excel 97-2003 files based on these manager groupings. So, for instance, 50 records containing value "SteveManag er" in the manager field would become an excel spreadsheet named SteveManager.xl s, and so on. This data is going to be overwritten every 3 months, so even creating 100 manual queries 1 time won't work because I would just have to redo it the next time since new managers are added/removed. Any help would be greatly appreciated!

    Jodie

    Can you post a reply to this thread on Wednesday/Thursday to bump it up the list. It may not get much attention over Christmas.

    Happy Holidays.

    Mary

    Comment

    • Killer42
      Recognized Expert Expert
      • Oct 2006
      • 8429

      #3
      Originally posted by mmccarthy
      Can you post a reply to this thread on Wednesday/Thursday to bump it up the list. It may not get much attention over Christmas.
      Sounds as though you'd probably want to use some VBA code to loop through the "manager values" and do a DoCmd TransferText for each.

      Comment

      • raneking22
        New Member
        • Dec 2006
        • 6

        #4
        What would be a good resource to find example of looping code to run through the managers? I may not have said this in my initial post, but I know very little VBA.

        Thanks,

        Jodie

        Comment

        • NeoPa
          Recognized Expert Moderator MVP
          • Oct 2006
          • 32669

          #5
          This isn't that easy for a newbie Jodie, but basically :
          1. Produce a query to list each manager including their name in the results (once only per manager).
          2. Process through this query in a VBA loop (there are examples of such things here in these forums).
          3. For each item create or update an existing QueryDef (saved Access Query) whose SQL restricts the output to those records matching your manager name.
          4. Using DoCmd.TransferS preadsheet, export this newly created or updated QueryDef to create each individual manager's spreadsheet.

          You may need help in some of these steps but let us know how far you get on your own first.

          Comment

          • MMcCarthy
            Recognized Expert MVP
            • Aug 2006
            • 14387

            #6
            Have a look at the following to get you started.

            Basic VBA recordset Query

            Happy New Year!

            Mary

            Comment

            • NeoPa
              Recognized Expert Moderator MVP
              • Oct 2006
              • 32669

              #7
              Originally posted by mmccarthy
              Have a look at the following to get you started.

              Basic VBA recordset Query

              Happy New Year!

              Mary
              Brilliant Mary!
              A great idea to put some basic code in a link like that.
              Now we just wait until KUB's ready with the new section so that people can find them a little more easily.

              -Ade.

              Comment

              Working...