Setting Value of Date Field

I want to set the value of a date field on a form (field name is oDateField).

If I use oDateField.Text it appears correctly, but it doesn’t read correctly as a date later in the process.

Is there another method to use to set the value of the field that is not connected to a table.


I thought this was answered in another post: Issues reading date field from a form

What makes this different?

That thread read the field. I am looking to set the field to the current date when the form loads now. The below runs on form load, but the oDateField.setValue(today) line throws an error.

Sub	OpenFormNewJobLabour()
	'msgbox "ADD NEW ITEM"
	Dim oForm As Object
	Dim oField As Object
	Dim oDateField As Object
	Dim today As New
	today.Month = Month( Now )
	today.Day = Day( Now )
	today.Year = Year( Now )

	'Set Job Field
	If iJobID = 0 Then Exit Sub
	oForm = ThisComponent.Drawpage.Forms.getByName("Job_Add_Labour")
    oField = oForm.getByName("Job_No")   'Get access to field'
    oField.Text = iJobId   'Move in value'
	iJobID = 0
	'Set date field to current
	oDateField = oForm.getByName("Labour_Date")   'Get access to field'

 End Sub

That thread also had a link to writing the date and time.


Using the link mentioned. this worked:




 	DocCtl = ThisComponent.getCurrentController()
  	CtlView = DocCtl.GetControl(oDateField)
1 Like