5 Replies Latest reply on Jan 8, 2015 7:38 PM by kimdavid

    Script to find a date range.

    DSM

      Title

      Script to find a date range.

      Post

      I have a table that has a Date field. The dates are entered as 20091231.

       

      I am trying to write a script that will find all records within a date range.

       

      I have two fields: StartDate and EndDate 

       

      Script:

       

      Enter find mode []

      Set field [Date;StartDate & "..." & EndDate]

      Perform Find

       

      I have also tried:

       

      Enter find mode []

      Insert Calculated Result [Select;Date;StartDate & "..." & EndDate]

      Perform Find

       

      After running these scripts, out of curiosity I clicked "Modify last find". Nothing was entered in the Date field.

      It is not possible that I have not selected the correct field in the script.

       

      I then tried:

       

      Enter find mode []

      Set field [Date;"20090901...20090902]

      Perform Find

       

      Did not work.

       

      I then clicked "modify last find" there was nothing in date field. I manually entered "20090901...20090902" and the find worked perfectly.

       

      I then tried a

       

      Perform Find [Restore] (Manually entering in the search criteria for the date field "20090901...20090902" and the find worked again. This however will not allow me to use fields or variables to perform a find. I can only enter the data in manually.

       

      Any help would be greatly appreciated.

       

       

       

       

        • 1. Re: Script to find a date range.
          philmodjunk
            

          It sounds like your three fields, Date, StartDate and EndDate are not all the same field type.

           

          If all three fields are the same type, all number, all text or all date, then the scripted approach with Set Field should do the job for you. (Insert calculated result will work also, but it requires you to have the target field present on the layout or it'll fail silently and that makes it less desirable.)

          • 2. Re: Script to find a date range.
            DSM
              

            Thanks Phil,

             

            I checked the field types. They are all text.

             

            The thing that has me really confused is this attempt that failed.

             

            I then tried:

             

            Enter find mode []

            Set field [Date;"20090901...20090902"]

            Perform Find

             

            Did not work.

             

            After this, I tried:

             

            Enter find mode []

            Set field [Date;"20090901"]

            Perform Find

             

            This did not work either.

             

            This field happens to be present in the layout, so I am not sure why it seems that the data I am entering into the script is not being entered into the field in Find Mode.

             

             

            • 3. Re: Script to find a date range.
              philmodjunk
                

              Just to check, I tested your example script on a database of a single text field named Date.

               

              It works for me with no trouble.

               

              Since these are text fields, other non visible text may be stored in the text field. You can check this by clicking in the field and trying to select all text contents.

               

              It's also possible that indexing on the field is corrupted. You can try turning indexing on and off to re-index the field.

               

               

              • 4. Re: Script to find a date range.
                DSM
                   I turned Indexing off and then back on for the date field and the script is now working. Thanks Phil.
                • 5. Re: Script to find a date range.
                  kimdavid

                  I want to know

                  when result value of "Enter find mode[]" is not, how to write a script.