7 Replies Latest reply on Sep 25, 2013 9:19 AM by philmodjunk

    Auto increment field number when record duplicated

    KarenThurman

      Title

      Auto increment field number when record duplicated

      Post

           Hi

           I am using FM12 and have a table in which I want to be able to duplicate records, so that I don't have to re-enter all the time when only one or two variables change. 

           I have created a Duplicate Record button which works okay but would also like to increment the number in a particular field by 1 as soon as the new record is created. Is there anyway I can do this?

           Thanks in anticipation

           Karen 

        • 1. Re: Auto increment field number when record duplicated
          philmodjunk

               Is there any reason why that field cannot be an auto-entered serial number?

               Otherwise, you'll need to use a script that both duplicates the record and increments the field.

          • 2. Re: Auto increment field number when record duplicated
            KarenThurman

                 Data for the field is being taken from a note book and will, more often than not, be the next number in the series but i sense auto numbering won't work in that sense.

                 The script option looks like the goer for me. I'm new to all this malarkey so wonder if you could tell me how to formulate one?

                  

                 Thanks

                 Karen

            • 3. Re: Auto increment field number when record duplicated
              philmodjunk

                   You'll have answer this question first:

                   As the numbers appear, will they all be of a single series, 1, 2, 3, 4, etc with each new value part of this one series or will there be different groups of records where the value must again start at one?

              • 4. Re: Auto increment field number when record duplicated
                KarenThurman

                     I think only ever increase by one in a single series. This is for recording the frames taken on a roll of film, so we will have a roll number and then want to increment the frames shot by one. If a new roll is used then the frame number will start from 1 but we will effectively in a new record set.

                • 5. Re: Auto increment field number when record duplicated
                  philmodjunk

                       Which is exactly what I meant by having more than one series of records. Each roll of film will start over with 1. Thus, an auto-entered serial number isn't likely to be practical.

                       Duplicate Record
                       Set Field [YourTable::FrameNumber ; YourTable::FrameNumber + 1 ]

                       Will duplicate the current record and increment the FrameNumber field by 1.

                       But if you have a table with one record for each frame, it would likely be a good idea to set up a related table with one record for each roll. Then you would have to enter data that is the same for every frame in the roll only once by entering it into a field in the related table.

                  • 6. Re: Auto increment field number when record duplicated
                    KarenThurman

                         Phil

                         Thanks for this. I have put in the duplicate record and set field script and it seems to work fine.

                         We do ultimately end up with one record for each frame but I am not sure how to go about the related table thing.

                         Thanks again

                          

                    • 7. Re: Auto increment field number when record duplicated
                      philmodjunk

                           Use Manage | Database | Tables to create a new table. Click the fields tab to add fields. Click the Relationships tab to link them in a relationship.

                           I recommend the following relationship:

                           Rolls-----<Frames

                           Rolls::__pkRollID = Frames::_fkRollID

                           For an explanation of the notation that I am using, see the first post of: Common Forum Relationship and Field Notations Explained

                           Then you can use a portal to Frames on your Rolls layout to create and complete records on each Frame or you can format the _fkRollID field on your Frames layout with a drop down list/pop up menu of RollID values plus a name or description from Rolls and use it to link a given Frame record to the correct record in the Rolls table. And there are ways to use Replace Field Contents to link all the records just imported (say by using Import Records | Folder to import a set of image files into a container field in Frames), to a specific record in Rolls.