Have tried this:
.Fields.Append .CreateField(strField, dbDate)
.Fields(strField).DefaultValue = "Null"
arrDateFormat(c) = newFieldArray(c)
For i = 1 To URowCount
If vArray(i, c) = 0 Then
vArray(i, c) = vbNull
End If
Next
It does make the default value show as Null, but I still get the 30/12/1899
values.
Maybe I should run the Update query on the table, but I am not familiar with
Access and
looping through the array is easier and maybe faster.
RBS
"Douglas J. Steele" <NOSPAM_djsteele@NOSPAM_canada.com> wrote in message
news:%23zL$(E-Mail Removed)...
> When you go into the table and see where the Default value is set to 0,
> remove that default value. It should be pretty obvious when you look at
> the field properties.
>
> --
> Doug Steele, Microsoft Access MVP
> http://I.Am/DougSteele
> (no private e-mails, please)
>
>
> "RB Smissaert" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> Thanks, how do I remove the 0 default in code?
>>
>> RBS
>>
>> "Arvin Meyer [MVP]" <(E-Mail Removed)> wrote in message
>> news:%(E-Mail Removed)...
>>> 30Dec1899 is 0, not null or empty. If you look in your table, you will
>>> find
>>> that the default for the column is 0. Remove that default and run an
>>> update
>>> query:
>>>
>>> UPDATE MyTable SET MyTable.[DateField] = Null
>>> WHERE (((MyTable.[DateField])=0));
>>>
>>> --
>>> Arvin Meyer, MCP, MVP
>>> Microsoft Access
>>> Free Access downloads
>>> http://www.datastrat.com
>>> http://www.mvps.org/access
>>>
>>> "RB Smissaert" <(E-Mail Removed)> wrote in message
>>> news:(E-Mail Removed)...
>>>> In Excel VBA I am showing a variant array in an Access table.
>>>> All working nicely, except when there is a date column
>>>> with empty dates these empty dates will show in Access as
>>>> 30/12/1899.
>>>>
>>>> The format of this date field is set like this:
>>>>
>>>> 'doing dbText is better for the rows with a value as
>>>> 'it will maintain the exact date format, but when there
>>>> 'is no value you will get 30/12/1899, now it will be
>>>> 00:00:00
>>>>
>>>> '------------------------------------------------------------
>>>> SetPropertyDAO tdfNew.Fields(arrDateFormat(c)), _
>>>> "Format", _
>>>> dbDate, _
>>>> strDateFormat
>>>>
>>>> strDateFormat is a string holding for example "dd/mmm/yyyy"
>>>>
>>>> The table is setup like this (code snippet only):
>>>>
>>>> 'First, create the database.
>>>> Set dB1 = DBEngine.CreateDatabase(strAccessFile, dbLangGeneral)
>>>>
>>>> 'Create a new TableDef object.
>>>> Set tdfNew = dB1.CreateTableDef(strSheetName)
>>>>
>>>> With tdfNew
>>>> ' Create fields and append them to the new TableDef
>>>> ' object. This must be done before appending the
>>>> ' TableDef object to the TableDefs collection database.
>>>>
>>>> .Fields.Append .CreateField(strField, dbDate)
>>>>
>>>>
>>>> How do I avoid this and at the same time format the non-empty dates?
>>>>
>>>> RBS
>>>
>>>
>>
>
>