Hi there,
I’ve been having an issue with programming a macro for a Base database form. I’ve been searching for an answer for hours and can’s seem to find a solution to my particular issue.
I’m trying to get a button to copy values from a the last record of a table into two entry field. The code works and the values appear in the fields on the form but I get an error when trying to save the record to the table saying that the fields are null. If I manually enter values into the fields or even just change one charater of the copied values then it will work. See code and error below.
Thanks in advance for any help.
Code:
query = "SELECT DatePurchased,OrderNumber FROM tblKeys WHERE ID = (SELECT MAX(ID) FROM tblKeys)"
oConn = ThisDatabaseDocument.DataSource.getConnection("","")
oQuery = oConn.createStatement()
oResult = oQuery.executeQuery(query)
If oResult.Next() Then
dateField.Date = oResult.getDate(1)
orderField.Text = oResult.getInt(2)
End If
Error:
Attempt to insert null into a non-nullable column:
column: DatePurchased table: tblKeys in statement
[INSERT INTO "tblKeys" ( "Key","ModelName","SerialNumber") VALUES ( ?,?,?)]
Edit: I am saving the record using another button with the Action set to “Save Record”.