AnsweredAssumed Answered

Go to record with closest date

Question asked by mjharding on Apr 20, 2017
Latest reply on Apr 25, 2017 by philmodjunk

Hello.

 

You help is greatly appreciated.

I am working on Filemaker 15.

The records are calendar events with a start and end date.

 

My goal is to go to the record in a found set who's start date is the closest to the current date - either in the past or future.  The frustrating part is my script works sometimes.  Very unFilemaker like.   Often, but not always, the record it goes to is not the one closest to the current date in the found set.   The line that doesn't always work is #9.    It doesn't always correctly determine if the calculated number of days is less then the previously set variable $days, even though my formula for that calculating the number of days - [  $days ; Value: Substitute (DayBack::DateStart - Get ( CurrentDate ); "-" ; "" )-  is always correct.

 

1.  Perform Find [ ]

2.  Go To Layout [ "Event Find"  (Dayback) ]

3.  Sort Records [ Restore ; With dialog: off ]

4.  Go to Record/Request/Page  [ First ]

5.  Set Variable  [  $days ; Value: Substitute (DayBack::DateStart - Get ( CurrentDate ); "-" ; "" )

6.  Set Variable  [  $record  ; Value:  Get  (RecordNumber ) ]

7.  Loop

8.         Go to Record/Request/Page  [ Next  ;  Exit after last ]

9.         If  [ Substitute (DayBack::DateStart - Get ( CurrentDate ); "-" ; "" )  <  $days

10.          Set Variable  [  $record  ; Value:  Get  (RecordNumber ) ]

11.          Set Variable  [  $days ; Value: Substitute (DayBack::DateStart - Get ( CurrentDate ); "-" ; "" )

12.       End If

13.       Exit Loop If  [  $days = 0  ]

14.  End Loop

15.  Go to Record/Request/Page  [ With dialog: Off  ;  $record  ]

 

Thank you !!

Outcomes