Clicking on a button does not put the focus on that button as you have discovered. This is by design so that you can put the cursor in a field and then click a button to perform a script that alters whichever field still has the focus.
What is not clear to me is why it matters whether or not the button has the focus. The button's script can check the two date fields and do nothing or display an error message if the two fields do not have valid dates. A conditional format can change the text color of label text in the button from black to a shade of grey to show it as "disabled" to let the user know that the correct data has not yet been entered. (But this is just an appearance change, you still have to include scripting that checks the values in the fields to so that nothing happens if the button is "greyed out".)
Thanks for your respons.
What happens (e.g.) is that the user is in the second field (ending date), and changed the second field. After this change the user is pushing directly the OK button. (without leaving the second field with the tab). (The button is providing a list). The dates are still valid, but the last change of the second field did not take place because the focus is still on the second field. By the way, the dates are global fields. I discovered that I don't have this problem with normal fields in a table. (I have, like you suggested, all my global fields in a separated table).
I also have buttons in other lay outs, and in those cases the button performs a script and the last change of the field the cursor is in, does take place. But not if it is a global field.
I don't see what that would create a problem, but if needed, the first line of your script can be Commit Records to make sure that the change to data in the second field has been committed to the database.
It is not a big problem, except that the user does not get the right list. No errors, just the wrong list.
What you suggested, Commit Records, I tried that, and it is working. To be honest, I couldn't find this one again because of the translation. Works fine. Thanks Phil. (In Dutch: Record/verzoek vastleggen ???)
I don't know what they call it in the Dutch version, but when you look at the list of script steps in the script editor, it's the Eighth item listed in the Records Category.
I found it Phil,
Maybe it is not only the way they translated it, but also the fact that I am so used to the English expressions, that I have problems finding the Dutch versions of these expressions. As I started in the IT industry, 38 years ago, everything was in English, there were no Dutch versions. And when possible, I still use English versions, although Dutch versions are available. But also the forum is in English, so as far as I am concerned, we keep everything in English.
Thanks for your effort Phil.