Page 1 of 1

[Solved] Set Datepicker default date to current date

Posted: Thu Jun 09, 2016 5:06 am
by raciret
Hello,

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

Thanks!

Re: Set Datepicker default date to current date

Posted: Thu Jun 09, 2016 5:35 am
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.

Re: Set Datepicker default date to current date

Posted: Thu Jun 09, 2016 5:40 am
by raciret
I used a data control for the datepicker.

Re: Set Datepicker default date to current date

Posted: Thu Jun 09, 2016 6:28 am
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 303 times

Re: Set Datepicker default date to current date

Posted: Fri Jun 10, 2016 8:32 am
by raciret
Thanks! I used the Date Field for the datepicker. does that formula apply to that as well?

Re: Set Datepicker default date to current date

Posted: Fri Jun 10, 2016 8:50 am
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?

Re: Set Datepicker default date to current date

Posted: Fri Jun 10, 2016 9:01 am
by raciret
I have attached sample file of date picker.

Thank you!

Re: Set Datepicker default date to current date

Posted: Fri Jun 10, 2016 9:08 am
by Zizi64
OooopS!!!
I see now:
Date Field.png

Re: Set Datepicker default date to current date

Posted: Fri Jun 10, 2016 9:22 am
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...

Re: Set Datepicker default date to current date

Posted: Fri Jun 10, 2016 2:34 pm
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" 

Re: Set Datepicker default date to current date

Posted: Mon Jun 13, 2016 8:30 am
by raciret
Thanks Villeroy! I'm new to OpenOffice so I'll have to study this. But thank you!

Thanks, everyone for the help!

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

Posted: Wed Jun 15, 2016 8:46 pm
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"