get date value from writer form via macro

I’m a long time OO user, now trying to migrate my apps to LO. Having trouble getting the date value from a form field - in OO I used this:

Dim oForm as Object,dobd as date
oForm = ThisComponent.DrawPage.Forms.getByName(“Main”)

print oForm.GetByName("PATIENT_FDN").Date

but LO appears to have date fields as a struct - according to MRI - how do I get the date value???

Hello,

If you want access to full date use:

print oForm.GetByName("PATIENT_FDN").Text

To get the individual elements:

print oForm.GetByName("PATIENT_FDN").Date.Day
print oForm.GetByName("PATIENT_FDN").Date.Month
print oForm.GetByName("PATIENT_FDN").Date.Year

Edit:

Here is sample: DateOnForm.odt

If this answers your question please tick the :heavy_check_mark: (upper left area of answer). It helps others to know there was an accepted answer.

Have just tried your code & works exactly as it should.

If I execute print oForm.GetByName(“PATIENT_FDN”).Text - I get a blank for the date which is not correct.

I can read the individual elements OK … and they are correct - e.g. 13, 04, 2006

This one app has over 35 forms, most of which need to check a date entered by the user.

I’ve made a simple form with one date field on it and a button to execute the following macro:

Sub Main
Dim Form as Object, dobs as string

Form = ThisComponent.DrawPage.Forms.getByName("Form")

print Form.getbyName("Date1").Text
print Form.getbyName("Date1").Date.Month
print Form.getbyName("Date1").Date.Day
print Form.getbyName("Date1").Date.year

End Sub

The output is blank for the statement, and the correct values for the rest…

I can’t see how to upload the simple form to this thread, but I could email it or ???

output is blank for the first print statement, and the correct values for the rest…

Please do NOT respond using an answer. Answers are to respond to original question. Either use a comment or Edit original question with the additional information.