vba Excel to Access: zero length string to Null number -
i have 2 values in same column in excel. select 1 of them , run following:
debug.print isnumeric(selection), _ vartype(selection), _ vartype(trim(selection)), _ ">" & selection.value & "<", _ len(trim(selection)), _ len(selection), _ selection.numberformat
then select other , run same debug.
and this:
- true, 5, 8, >9.46979663546499<, 16, 16, general
- false, 8, 8, ><, 0, 0, general
note: column has multiple occurrences of both
- can explain this? i've been vba'ing , excel'ing long time , still don't (in detail) number formatting excel , how work them best. think have stumble upon new this.
- in case objective ms access automatically understand column double/number/float/whatever column can null when import , not throw errors. have achieve through formatting/changing in excel prior importing it. (partly because work best client's processes , partly because want head around finally...can't believe don't already!) have on 2000 rows change each column solution formats entire column @ once best, not 1 cell @ time.
thanks!
isnumeric returns true number , false blank. i'm not sure if unexpected, ms had make return 1 or other. logic blank neither numeric or text.
vartype returns double number (as expected). if vartype empty cell, vbempty (0), not 8 (excel 2010 x86). if put single apostrophe in cell, same you.
when trim() something, convert text. doesn't matter trim, trim function returns string, vartype 8.
read post on mixed data types http://dailydoseofexcel.com/archives/2004/06/03/external-data-mixed-data-types/. make sure read comments.
when office program imports, uses registry keys determine data types. typically, reads first 8 rows of field determine data type is. if sees mixture of data types, picks majority , converts or ignores else. can change registry settings @ more 8 rows or default text, can't tell treat empty cells numbers.
it nice if ignore empty cells , take majority of rest. 'empty cell' not concept outside of excel doesn't surprise me.
the right answer you, think, create schema file , put in same directory file you're going import. read @ https://msdn.microsoft.com/en-us/library/ms709353%28v=vs.85%29.aspx setting column data types in file.
i use every day in excel vba - use vba create schema.ini file, then use ado read in file. haven't ever used in access, particularly importing through ui. it's worth try. if doesn't work, can importing in vba , ado.
Comments
Post a Comment