Ask Your Question

get date value from writer form via macro

asked 2018-05-06 19:38:48 +0100

GaryK gravatar image

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???

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted

answered 2018-05-06 22:46:31 +0100

GaryK gravatar image

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 ???

edit flag offensive delete link more


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

GaryK gravatar imageGaryK ( 2018-05-06 22:48:18 +0100 )edit

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.

Ratslinger gravatar imageRatslinger ( 2018-05-06 23:03:26 +0100 )edit

answered 2018-05-06 20:03:03 +0100

Ratslinger gravatar image

updated 2018-05-06 23:08:54 +0100


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


Here is sample: DateOnForm.odt

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

edit flag offensive delete link more


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

Ratslinger gravatar imageRatslinger ( 2018-05-06 23:16:03 +0100 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2018-05-06 19:38:48 +0100

Seen: 57 times

Last updated: May 06 '18