Date fields can be cleared in a few ways, but the wanted end result is more important. The first way is pretty simple:
Sub ClearField
oForm = ThisComponent.Drawpage.Forms.getByName("MainForm") 'Get Form'
oField = oForm.getByName("dateOrder")
oField.Text = " "
oField.Text = ""
End Sub
The reason for the two oField.Text lines is that first you must move something into the field before you can change it to empty. You can’t leave it as a space because it is not a valid date. Another way is to do it through the view:
Sub ClearField
oForm = ThisComponent.Drawpage.Forms.getByName("MainForm") 'Get Form'
Doc = ThisComponent
oField = oForm.getByName("dateOrder")
DocCtl = Doc.getCurrentController()
'Get VIEW for listbox'
CtlView = DocCtl.GetControl(oField)
CtlView.setEmpty()
End Sub
This will clear the viewed field just as the first example. Just know that is all these two routines do - remove the viewed content.
If this is a database field, however, and you are trying to delete it, more needs to be done. Adding this line:
CtlView.setFocus()
to the end of the last routine will prepare the field to be updated as a blank field (if you’ve allowed that) and adding this line:
oForm.updateRow()
completes the update of the blank date field. To actually change the date use:
Dim aDate As New com.sun.star.util.Date
'Used to get the date'
aDate = CtlView.getDate()
myDay = aDate.Day
myMonth = aDate.Month
myYear = aDate.Year
'Used to set a date'
aDate.Day = 02
aDate.Month = 28
aDate.Year = 16
CtlView.setDate(aDate)