Search code examples
filemaker

FMP 14 - Auto Populate a Field based on a calculation


I am using FMP 14 and would like to auto-populate field A based on the following calulation:

If ( Get ( ActiveLayoutObjectName ) = "tab_Visits_v1" ; "1st" ) or
If ( Get ( ActiveLayoutObjectName ) = "tab_Visits_v2" ; "2nd" ) or
If ( Get ( ActiveLayoutObjectName ) = "tab_Visits_v3" ; "3rd" ) or
If ( Get ( ActiveLayoutObjectName ) = "tab_Visits_v4" ; "4th" ) or
If ( Get ( ActiveLayoutObjectName ) = "tab_Visits_v5" ; "5th" ) or
If ( Get ( ActiveLayoutObjectName ) = "tab_Visits_v6" ; "6th" ) 

The above code is supposed to auto-populate the value 1st, 2nd, 3rd ... in field A depending on the name of the object the Get (ActiveLayoutObjectName) function returns. I have named each of my tabs, but the calculation is only returning 0.

Any help would be appreciated.

thanks.


Solution

  • The way your calculation is written makes very little sense. Each one of the If() statements returns a result of either "1st", "2nd", etc. or nothing (an empty string). You are then applying or to all these results. Since only of them can be true, your calculation is essentially doing something like:

     "" or "2nd" or "" or "" or "" or ""
    

    which happens to return 1 (true), but has no useful meaning.

    You should be using the Case() function here:

    Case ( 
    Get ( ActiveLayoutObjectName ) = "tab_Visits_v1" ; "1st" ; 
    Get ( ActiveLayoutObjectName ) = "tab_Visits_v2" ; "2nd" ; 
    Get ( ActiveLayoutObjectName ) = "tab_Visits_v3" ; "3rd" ; 
    Get ( ActiveLayoutObjectName ) = "tab_Visits_v4" ; "4th" ; 
    Get ( ActiveLayoutObjectName ) = "tab_Visits_v5" ; "5th" ; 
    Get ( ActiveLayoutObjectName ) = "tab_Visits_v6" ; "6th" 
    ) 
    

    Note also that a calculation field may not always refresh itself as a result of user switching a tab. This refers to an unstored calculation field; if you are trying to use this as the formula to be auto-entered into a "regular' (e.g. Text) field, it will never update.


    Added:

    Here is our situation. We see a patient a maximum of 6 times. We have a tab for each one of those 6 visits.

    I would suggest you use a portal to a related table of Visits instead of a tab control. A tab control is designed to display fixed components of user interface - not dynamic data. And certainly not data split into separate records. You should have only one unique record for each patient - and as many records for each patient's visits as may be necessary (potentially unlimited).

    If you like, you can use the portal rows as buttons to select a specific visit to view in more detail (similar to a tab control, except that the portal shows the "tabs" as vertical rows). A one-row portal to the same Visits table, filtered by the user selection, would work very well for this purpose, I believe.