7 Replies Latest reply on Jul 10, 2014 6:33 PM by TysonBoelman

    Help with loop



      Help with loop


           I've got a database that I'm trying to make to track hours of contractors we hire during a job. I have two layouts built, both of them are almost the same thing but on my main page I have start / stop times with totals, the location, the job number and the contractors name. On the other page it has all the same stuff but just has more places to enter different contractors who were working that same job and times. I've built a script step that will copy the information and store it into a variable then go to the single contractor layout and make a new record and paste all the information into the fields.

           The reason for this is to make it a bit faster to enter daily times for a large group of people on one layout and let the script step do the labor for me.

           The main layout is called Time Sheets, this is the one that has only one contractor in it. The other layout, the one I'm exporting this information from and has multiple contractors listed is called Adding Data


           So I have 11 fields available to enter a contractors name into on my Adding Data layout,



           Contractors Copy

           Contractors Copy2...... all the way to 10


           Also have a loop calculation field that will tell me when I hit an empty field to exit the loop so that I'm not making a copy of empty contractor field names and creating time sheets for nobody.


           My question is how to start the loop, I don't know how to say

           start at field:contractors


           do your magic

           go to contractors copy

           do your magic

           go to contractors copy2

           end loop if

           exit loop

           and where do i put the exit loop if?


           Thanks in advance

        • 1. Re: Help with loop

                    So I have 11 fields available to enter a contractors name into on my Adding Data layout,

               A better approach is to have 11 records, one record for each contractor. It makes reporting much simpler in most cases and you are no longer limited to a maximum of 11 contractors when you use records instead of fields.

               And looping through records is a lot simpler than looping through fields.

          • 2. Re: Help with loop


                 agreed looping through records is a lot better than fields but the idea is that these are for contractors and not full time employees so they change on a daily basis. Having a record that will allow me to enter their names in once and generate a new record for each name would work best for my situation. Thanks for the fast response.

            • 3. Re: Help with loop

                        but the idea is that these are for contractors and not full time employees so they change on a daily basis.

                   Sorry but I see no advantages for you in using a set of fields with one field for each contractor instead of a set of records with one record for each contractor. These can be displayed in a layout as a set of list view records or in a portal. The data entry task becomes much the same, but the script, and the data becomes much easier to work with.

              • 4. Re: Help with loop

                     As far as for reports, it will end up looking the same because in the end, you have a record for each contractor but the whole point is so I can say
                      these 5 contractors worked from 7am to 5pm on this date at this location but only have to update one record, instead of 5

                • 5. Re: Help with loop

                       Phil is giving you excellent advice regarding the advantage of records over fields.  You can hardly expect to request & receive specifically non-optimal solutions.  Imagine this: instead of 11 fields, you simply have one portal.  To enter a new contractor, you simply go to the last row and enter the new contractor & his or her hours.  Or, if you've already used this contractor- select him/her from a list.  Done.  Contractors and hours are associated by being on the same record.  For individual layouts- no need to copy or paste anything anymore.

                       If you want run a looping script (to, say, set all the starting times on all the contractors to be 9am), with a portal you simply make the last instruction in the loop- go to next portal row & if it's the last, exit loop.  Done.  You're using filemaker like a spreadsheet, but if you take the time to learn to use it as a relational database, you will be much better off.

                       Your situtation is like *the* classic example of how relational databases are an excellent alternative to listing fields.  Just because a person is a 'record' in your database doesn't make them a 'part' of your organization.  

                       Anyways, that's the basic idea.  Phil will no doubt be able to offer a more optimal solution for you as he has for me on many occasions.

                  • 6. Re: Help with loop

                         You may find it enlightening to look at this thread where different circumstances require looping through fields in the same record. Note some of the complexities involved in getting that to work: Problems displaying 1 to 1 fields on a layout

                    • 7. Re: Help with loop

                           I guess taking a step back and looking at this as a database rather than a spreadsheet has really helped to take this project back to the drawing board. Thanks for the suggestions guys and I'll post later when I get something going. Thanks again everybody