Hi- Trying to get a form to auto fill a date field with the current date. Have searched both google and this forum and another and what I found went way over my head or it referenced a SQL database which I am pretty sure I am not using unless it always uses SQL. I am VERY new to base(or anything to do with db's).
In my table under the field of the entry date, I tried to use CURDATE() as the default value but that just inputs 01/01/1800 as the date in my form. I did not setup any SQL stuff(this is VERY simple db just to learn abit about db's and to track my freebie/samples that I order). I read quite a few suggestions that mention macros, but I feel that is way over my head. It just seems that there should be an easy way to set up a date field to use the current date as a default but maybe my expectations are to high. Any ideas/tips/macros for dummies topics you could point me to?
Thank you
Getting date field auto filled with current date
Getting date field auto filled with current date
OOo 3.1.X on Ms Windows XP
Re: Getting date field auto filled with current date
[Solved] Automatic timestamp assignment how?I am VERY new to base(or anything to do with db's). ...
AOO 4.0 and LibO 4 on Win 8
Hungarian forum co-admin
Hungarian forum co-admin
Re: Getting date field auto filled with current date
Hi, this used to be my nightmare since I discovered a BoundField through Xray...
Here is my code (used for a cell of table grid):
Explanation:
...
Have much fun with it.
Here is my code (used for a cell of table grid):
Code: Select all
Sub FillToday(oev As Object)
If oev.source.model.BoundField.Long=0 Then
Dim d As new com.sun.star.util.Date
d.Day=Day(Date())
d.Month=Month(Date())
d.Year=Year(Date())
oev.source.model.BoundField.Value=d
End If
End Sub
- oev - event object of a form element
- BoundField has a WriteOnly property Value which is a Date struct in DateField, so U need to send to it the same struct -
. To read a BoundField value U can use every possible cast - Long, Int, String, whatever...com.sun.star.util.Date

Have much fun with it.

OOffice 3.2 Debian Squeeze
Re: Getting date field auto filled with current date
Hi! after a lot of blanqe nights I've find this very low level solution:
=========================================================
'from italian date to dateserial for form inserting
Function datait_serial(data_it As String) As Integer
Dim arr As Variant
arr = split(data_it, "/")
If UBound(arr)<2 Then Exit Function
datait_serial = dateserial(arr(2),arr(1),arr(0))
End Function
'from italian date to SQL date (ie 05/02/1999 -> 1999-02-05)
Function datait_sql(data_it As String) As String
Dim arr As Variant
arr = split(data_it, "/")
'se già in formato sql esci
If Ubound(arr)=0 Then
arr = split(data_it, "-")
If Ubound(arr)=2 Then
datait_sql=data_it
Exit Function
Endif
Endif
datait_sql = arr(2) & "-" & arr(1) & "-" & arr(0)
End Function
Sub sticazzi(e)
.....
dtNsc="10/04/1985"
.....
Form=e.source.model.parent
ctl = Form.getByName("datdata_nascita")
ctl.boundfield.updateint(int(datait_serial(dtNsc)))
ctl.boundfield.updateString(datait_sql(dtNsc))
End Sub
EVVIVA !!!!!!!!!!!!!!!!!!!!!!!!!

=========================================================
'from italian date to dateserial for form inserting
Function datait_serial(data_it As String) As Integer
Dim arr As Variant
arr = split(data_it, "/")
If UBound(arr)<2 Then Exit Function
datait_serial = dateserial(arr(2),arr(1),arr(0))
End Function
'from italian date to SQL date (ie 05/02/1999 -> 1999-02-05)
Function datait_sql(data_it As String) As String
Dim arr As Variant
arr = split(data_it, "/")
'se già in formato sql esci
If Ubound(arr)=0 Then
arr = split(data_it, "-")
If Ubound(arr)=2 Then
datait_sql=data_it
Exit Function
Endif
Endif
datait_sql = arr(2) & "-" & arr(1) & "-" & arr(0)
End Function
Sub sticazzi(e)
.....
dtNsc="10/04/1985"
.....
Form=e.source.model.parent
ctl = Form.getByName("datdata_nascita")
ctl.boundfield.updateint(int(datait_serial(dtNsc)))
ctl.boundfield.updateString(datait_sql(dtNsc))
End Sub


EVVIVA !!!!!!!!!!!!!!!!!!!!!!!!!




Libreoffice Versione: 6.4.5.2 Build ID: 6.4.5-1 Thread CPU: 4; SO: Linux 5.4; Resa interfaccia: predefinito; VCL: gtk3;
talessx
Arch Linux
talessx
Arch Linux
Re: Getting date field auto filled with current date
Without any macro you can define the current date as default value for the table. It is inserted when you save a new record with the date missing.
menu:Tools>SQL...
replace "tbl" and "col" with the actual names of table and column.
[Execute]
then activate the tables section and call menu:>View>Refresh Tables
For times:
For time stamps:
This will _not_ insert any data into the form which would be pointless when using a time stamp field because there may be minutes or hours between loading the form and actually storing its content.
You can omit the date/time column on the form and leave it up to the database.
You can add some label such as "Date (current date when missing)"
menu:Tools>SQL...
Code: Select all
ALTER TABLE "tbl" ALTER COLUMN "col" DATE DEFAULT CURRENT_DATE
[Execute]
then activate the tables section and call menu:>View>Refresh Tables
For times:
Code: Select all
ALTER TABLE "tbl" ALTER COLUMN "col" DATE DEFAULT CURRENT_TIME
Code: Select all
ALTER TABLE "tbl" ALTER COLUMN "col" DATE DEFAULT CURRENT_TIMESTAMP
You can omit the date/time column on the form and leave it up to the database.
You can add some label such as "Date (current date when missing)"
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
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Re: Getting date field auto filled with current date
Ok thanks!
However sometimes it's useful to insert dates different from the present time, fetching dates from external data.
For exemple the fiscal code DNDMSM66P04H501M means you are born in Rome on 04/09/1966 and this can be automatically obtained using a macro script.
However sometimes it's useful to insert dates different from the present time, fetching dates from external data.
For exemple the fiscal code DNDMSM66P04H501M means you are born in Rome on 04/09/1966 and this can be automatically obtained using a macro script.
Libreoffice Versione: 6.4.5.2 Build ID: 6.4.5-1 Thread CPU: 4; SO: Linux 5.4; Resa interfaccia: predefinito; VCL: gtk3;
talessx
Arch Linux
talessx
Arch Linux