[Solved] Default date field to today with macro

Creating and using forms
Post Reply
contremaitre
Posts: 16
Joined: Fri Feb 20, 2015 10:58 pm

[Solved] Default date field to today with macro

Post by contremaitre »

Hi,

I spent hours searching in google how to set today date in a form with a macro and couldn't find a solution (the only solution given was to add a SQL command to default new record but it's not working when the date field is not attached to a table row)
So I thought I would share mine here, hope this is a good place.

- Create a macro like :

Code: Select all

Sub SetDate (oEvent As Object)
	oForm = oEvent.Source
	oForm.getByName("inputDate").Text = Date()
End Sub
Call this macro on "loading" event of the form containing the input date.
Openoffice 4.3 Kubuntu 14.10
F3K Total
Volunteer
Posts: 1038
Joined: Fri Dec 16, 2011 8:20 pm

Re: HOWTO : default date field to today with macro

Post by F3K Total »

Hi,
if you just want to display todays date, you can do it without a macro, by using e.g. this SQL Command as form content:

Code: Select all

SELECT CURRENT_DATE CD FROM INFORMATION_SCHEMA.SYSTEM_TABLES WHERE TABLE_NAME = 'SYSTEM_ALIASES'
See attached example. Note, that where using an already existing table from INFORMATION_SCHEMA to display CURRENT_DATE within a formatted field.
R
EDIT: Villeroys solution, see next post, is once more much easier. For tryout, I added it to the example file.
Attachments
CURRENT_DATE.odb
(10.92 KiB) Downloaded 457 times
Last edited by F3K Total on Sun Mar 15, 2015 8:39 pm, edited 2 times in total.
  • MMove 1.0.6
  • Extension for easy, exact positioning of shapes, pictures, controls, frames ...
  • my current system
  • Windows 10 AOO, LOLinux Mint AOO, LO
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: HOWTO : default date field to today with macro

Post by Villeroy »

contremaitre wrote:Hi,
... (the only solution given was to add a SQL command to default new record but it's not working when the date field is not attached to a table row)
In that case you can simply use menu:Insert>Fields>Other , tab "Document" Date (not the fixed one).
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
contremaitre
Posts: 16
Joined: Fri Feb 20, 2015 10:58 pm

Re: [Solved] Default date field to today with macro

Post by contremaitre »

Thanks, but it seems your solutions can only display the date.
I need a field where the user can change it, maybe I was not clear enough in my original post.
Openoffice 4.3 Kubuntu 14.10
Post Reply