[Solved] Set Datepicker default date to current date

Discuss the spreadsheet application
Post Reply
raciret
Posts: 11
Joined: Thu Mar 03, 2016 7:17 am

[Solved] Set Datepicker default date to current date

Post by raciret »

Hello,

Is there a way to set the default date of a datepicker to the current date?

Thanks!
Last edited by raciret on Mon Jun 13, 2016 8:36 am, edited 2 times in total.
OpenOffice 4 on Windows 10
User avatar
RusselB
Moderator
Posts: 6646
Joined: Fri Jan 03, 2014 7:31 am
Location: Sarnia, ON

Re: Set Datepicker default date to current date

Post by RusselB »

If this is a drop down list (aka Data Validity) and the Allow field is set for Cell Range, then simply put

Code: Select all

=today() 
into a cell that is in the range.
If you have something else for your date picker, please provide more information so that we can determine other possibilities.
OpenOffice 4.1.7, LibreOffice 7.0.1.2 on Windows 7 Pro, Ultimate & Windows 10 Home (2004)
If you believe your problem has been resolved, please go to your first post in this topic, click the Edit button and add [Solved] to the beginning of the Subject line.
raciret
Posts: 11
Joined: Thu Mar 03, 2016 7:17 am

Re: Set Datepicker default date to current date

Post by raciret »

I used a data control for the datepicker.
OpenOffice 4 on Windows 10
User avatar
Zizi64
Volunteer
Posts: 11511
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Set Datepicker default date to current date

Post by Zizi64 »

I used a data control for the datepicker.
It is a List Box, or a Combo Box? Then you set the source to a cellrange, and you can put the = TODAY() formula into the cellrange...
Combobox TODAY().ods
(8.8 KiB) Downloaded 302 times
Tibor Kovacs, Hungary; LO7.5.8/25.8.5.2 /Win7-10-11 x64Prof.
PortableApps: LO3.3.0-25.8.5.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
raciret
Posts: 11
Joined: Thu Mar 03, 2016 7:17 am

Re: Set Datepicker default date to current date

Post by raciret »

Thanks! I used the Date Field for the datepicker. does that formula apply to that as well?
OpenOffice 4 on Windows 10
User avatar
Zizi64
Volunteer
Posts: 11511
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Set Datepicker default date to current date

Post by Zizi64 »

I used the Date Field for the datepicker.
I never used that 'Date Field' in the Calc. You can not insert a Writer-type 'Text Field' into a Spreadsheet. Do you mean the Formatted Field?
Formatted Field.png

Or:
Can you upload your example .ods file here with the applied "datepicker"?
Is it a StarBasic/API related question?
Last edited by Zizi64 on Fri Jun 10, 2016 9:03 am, edited 1 time in total.
Tibor Kovacs, Hungary; LO7.5.8/25.8.5.2 /Win7-10-11 x64Prof.
PortableApps: LO3.3.0-25.8.5.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
raciret
Posts: 11
Joined: Thu Mar 03, 2016 7:17 am

Re: Set Datepicker default date to current date

Post by raciret »

I have attached sample file of date picker.

Thank you!
Attachments
Date Picker.ods
(11.19 KiB) Downloaded 356 times
OpenOffice 4 on Windows 10
User avatar
Zizi64
Volunteer
Posts: 11511
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Set Datepicker default date to current date

Post by Zizi64 »

OooopS!!!
I see now:
Date Field.png
Tibor Kovacs, Hungary; LO7.5.8/25.8.5.2 /Win7-10-11 x64Prof.
PortableApps: LO3.3.0-25.8.5.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
User avatar
Zizi64
Volunteer
Posts: 11511
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Set Datepicker default date to current date

Post by Zizi64 »

Date Picker.ods
I get a macro error massage, when I tried your file. There is not macro code in your example file...
Tibor Kovacs, Hungary; LO7.5.8/25.8.5.2 /Win7-10-11 x64Prof.
PortableApps: LO3.3.0-25.8.5.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
User avatar
Villeroy
Volunteer
Posts: 31365
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Set Datepicker default date to current date

Post by Villeroy »

As always, this would be a perfect job for a database. Difficult to set up, easier to use and with no macro code.
Anyway: viewtopic.php?f=74&t=82181

Code: Select all

if isUnoStruct(objDateControl.getValue()) then
  sType = "UNODATE" 'LibreOffice
else
  sType = "INTDATE" 'OpenOffice
endif
basicDate = Now
vDate = ConvertDateTime(basicDate, sType)
objDateControl.setDate(vDate)
 Edit: Sorry, the StarBasic language has no Today function. I replaced "Today" with "Now" 
Last edited by Villeroy on Thu Jun 16, 2016 2:47 pm, edited 2 times in total.
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
raciret
Posts: 11
Joined: Thu Mar 03, 2016 7:17 am

Re: Set Datepicker default date to current date

Post by raciret »

Thanks Villeroy! I'm new to OpenOffice so I'll have to study this. But thank you!

Thanks, everyone for the help!
OpenOffice 4 on Windows 10
User avatar
Villeroy
Volunteer
Posts: 31365
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: [Solved] Set Datepicker default date to current date

Post by Villeroy »

If your maro is supposed to run with OpenOffice only:

Code: Select all

intDate = ConvertDateTime(Now, "INTDATE")
objDateControl.setDate(intDate)
If you hate wrapper functions, the conversion from Basic Today into the right 8-digit integer goes like this:

Code: Select all

intDate = cLng(Format(Year(Now), "0000") & Format(Month(Now), "00") & Format(Day(Now), "00"))
objDateControl.setDate(intDate)
 Edit: Sorry, the StarBasic language has no Today function. I replaced "Today" with "Now" 
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
Post Reply