How can I do form data entry via a macro?

Base Version 4.3.5.2 on Fedora 21.
I have a data entry form for an inventory database. The first field is a Date. The appropriate entry for the date field is almost always today’s date. Therefore, I want to programatically enter today’s date into the first field for the first new database row and if it’s incorrect for the occasion the user can change it. All additional rows should repeat whatever was entered in the previous row for date as the information is typically coming from a long invoice.

Option Explicit
Global defaultDate           as string

Sub Main
defaultDate = Date
End Sub

Sub PriorToReset(event)
dim Form
dim DateField
MsgBox ("defaultDate = " + defaultDate)         ' for testing
Form=event.source
DateField = Form.getByName("Date")

if DateField.getPropertyValue("Text") = "" then
   DateField.setPropertyValue("Text", defaultDate)
   MsgBox ("Setting default to " + DateField.getPropertyValue("Text"))          'for testing
else
   defaultDate = DateField.getPropertyValue("Text")
end if
End Sub

First problem:
Using Xray, I can see that the code is working as expected. However, when the rest of the row is filled in, an error pops up saying the date field is empty. I’m looking at that field on the screen and it has today’s date in it but the system reacts as though it was empty. If I focus that field, and backspace over just the last digit and then replace that digit, it accepts the whole field as valid. i.e. if I see 01/03/2015 and backspace over the 5 and then key in the 5 all is well and a new row shows up. What am I missing?

Second problem:
The new row has a blank date field, but using Xray, the “Text” property has today’s date in it. There’s a disconnect here I don’t understand.

Use the .commit() method on the field that you are updating. Use that in tandem with every programmatic update of a field. A form is composed of many parts or layers, like the origial form object, the rowset in the data source, and the controller. The .commit() method sends the content of the form control to the data source it is bound to (see API reference).