3 Replies Latest reply on Jan 11, 2014 11:00 PM by philmodjunk

    Count Times Record Exported

    chadmccomas

      Title

      Count Times Record Exported

      Post

           I have a button to export records.  What I want to happen is this:

           1. Go to layout 

           2. Show Records where Exported Field > 5

           3. Export Found Records

           4. Add 1 to Exported Field.  

           The exported field auto-enters 0 when a record is imported.  The idea is that if I export a record, then that changes to 1.  Then 2 when exported again.  And so forth.  But records that have 5 or more are ignored.

           Is there a way to do this?  I tried to set up a loop but then that exported each record as its own file and I ended up with 200,000+ csv files on my desktop.  That wasn't good.  : (

        • 1. Re: Count Times Record Exported
          philmodjunk

               Go to Layout
               Enter Find Mode []
               Set Field [YourTable::ExportCount ; "<" & 5 ]
               Set Error Capture [on]
               Perform Find []
               If [ Get ( FoundCount ) //There are records found to export ]
                  Export Records
                  Replace Field Contents [ no dialog; YourTable::ExportCount ; YourTable::ExportCount + 1 ]
               Else
                  Show Custom dialog ["No records were found to export"]
               End IF

          • 2. Re: Count Times Record Exported
            chadmccomas

                 That works fine.  I have a few questions though if you don't mind.  I want to understand why this is working.

            So it is doing this:


            Set Field [YourTable::ExportCount ; "<" & 5 ]

                 On this one, I think it is saying "Let's find every record that YourTable::ExportCount is less than 5?   What is the & symbol for?  Why can't it just be < 5?

            Set Error Capture [on]

            What is this doing?   I dig it is capturing errors.  But what for?


            Perform Find []
            If [ Get ( FoundCount ) //There are records found to export ]

            So this is saying that if the results of the < & 5 above has any results than move forward or show the dialog?


               Export Records
               Replace Field Contents [ no dialog; YourTable::ExportCount ; YourTable::ExportCount + 1 ]
            Else
               Show Custom dialog ["No records were found to export"]
            End IF

            Also, so when you put Perform Find and then have another command immediately after - is that second command part of the Find?

                  

            Thanks!

            • 3. Re: Count Times Record Exported
              philmodjunk
                   

                        What is the & symbol for?  Why can't it just be < 5?

                   It could be. The & is a concatenation operator that combines the "<" with 5. What you can do in some variations of this method is replace the 5 with a variable or global field to create a script that can use different, user specified data in the find. But if you are just going to always use 5, there's no reason not to just use: "<5" and leave out the &.

                   

              What is this doing?

              If a scripted find fails to find any records, an error message will interrupt your script telling you that no records were found and presenting the user with options for canceling the script, continuing the script or modifying the find criteria. Set Error Capture keeps this and nearly all other error dialogs from appearing and interrupting the script like this.

                   

              So this is saying,,,

              Yes

                   

              Also, so when you put Perform Find and then have another command immediately after - is that second command part of the Find?

                   No. Perform Find returns the layout to browse mode as well as pulling up a found set of all records that match the specified criteria. Since we have supressed the error dialog, the following steps supply one that does not create possible issues for the user.