If I use the following code I can enter the current date as a serial number whose Data Type is
Integer. If I copy this number into a Calc cell and format that cell as a date, it gives me the
correct date.This leads me back to my suspicion that my problem is the way Base handles dates.
I tried formatting the number 1 as a date with the format DD/MM/YYYY. In Calc, Excel and Base I
formatted the cells and query columns. In Access I used the Format function Format(MyNumber,
"DD/MM/YYYY") The results are:
Calc = 31/12/1899
MS Access = 31/12/1899
Excel = 1/1/1900 (!)
In Base however, if I format any number, no matter which, I get 03/01/1. ie BASE does not seem to
treat dates as serial numbers by the time it gets into a database, even thought OfficeBasic does.
Interestingly in MS Access and Calc, entering -1 gives me 29/12/1899;in Excel I get a row of #
symbols - it can't handle these earlier dates. So if you're a historian who wants to create
statistical data, it is Calc rather than Excel which you need.
Code: Select all
Sub WriteToField(oEvent As Object)
'IntField is defined in my table as an Integer data type
Dim MyForm As Object
Dim MyField As Object
Dim MyDate as string
Dim MyRealDate As Long
'even though I was hoping for a Date value
Dim MyFieldName As String
MyRealDate = CLng(Date)
'change the string into a date serial with
'the CLng function
MyFieldName = "IntField"
'the name of the actual table field
MyForm = ThisComponent.Drawpage.Forms.getbyName("MainForm")
MyField = MyForm.Columns.GetByName(MyFieldName)
MyField.Value = MyRealDate
'enters today's date as a serial number
'which in Calc, or even MS Access, but not in Base,
'can be formatted as the current date
'by just formatting the cell/field that contains it
End Sub