0

Switching to next year

Hello everyone, I hope you're all well! I don't know if this question is already asked, but here's the deal: I have a table containing 2 fields-1 text field and 1 date field. It shows the dates of the "name day" for each name. I would like this table to refresh every new year, so if a name has its name day on November 11, 2022, I want to be able with a single action replace the date to November 11, 2023 and so on! is there a way to do that?

Thank you so much in advance.

Best regards

9 replies

null
    • pirinisz
    • 2 yrs ago
    • Reported - view

    Also, one more thing: I want these 2 fields to be imported in another table, where I already put a field (name) that I choose from the 1st field, but I want to auto insert the date field on the same record! Any suggestions on that??

    • pirinisz
    • 2 yrs ago
    • Reported - view

    Scratch the 2nd question, I found out how to do that! I just need help with the year replacement from the 1st question!

    Thanks you guys!

    • Lars
    • 2 yrs ago
    • Reported - view

    The formula update the datefield is

    if today() > datefield then
        datefield := date(year(today())+1, month(datefield), day(datefield))
    end;
    
      • pirinisz
      • 2 yrs ago
      • Reported - view

      Lars You mean I should create a formula field within the table or put this code in the date field???

      • pirinisz
      • 2 yrs ago
      • Reported - view

      Lars I also noticed that this works with any new record I create, but what about the old records? Will they auto refresh somehow or should I do something about it?

      Thank you so much for this info!

      • Fred
      • 2 yrs ago
      • Reported - view

      If you want to affect all records in table you have options:

      1) You can select update multiple records under the Gear icon and then select Assign Calculated value then put this in the formula:

      datefieldname + 365
      

      Then click OK. Then click Next and you will see what value Ninox will put in the date field.

      2) You can create a button that you press once a year. You can put this in the On Click field:

      for loop1 in select TableName do
      loop1.(DateFieldName := DateFieldName + 365)
      end
      

      But be careful with this because this will change all records in your table.

      • pirinisz
      • 2 yrs ago
      • Reported - view

      Fred One other option I thought about is adding the code you sent me:

      if today() > datefield then
          datefield := date(year(today())+1, month(datefield), day(datefield))
      end;
      to the "Trigger after open" field of the database options:

      I just don't know how to refer to the specific table, because this: if today() > datefield then

      is not enough to trigger, we need to tell it in which table the field is located!!!

    • John_Halls
    • 2 yrs ago
    • Reported - view

    You are correct, if you put it in the Trigger after open: then it needs to know the table and records, so change the code to something like this

    for a in select tablename where today() > datefield do
        a.datefield := date(year(today())+1, month(a.datefield), day(a.datefield))
    end;
    

    Regards John

      • pirinisz
      • 2 yrs ago
      • Reported - view

      John Halls Worked like a charm! Thank you so much! You made me happy!! 😄

       

      Best regards

Content aside

  • 2 yrs agoLast active
  • 9Replies
  • 84Views
  • 4 Following