How to import 18 digit numbers as text from XML (1 Viewer)

marlan

Registered User.
Local time
Tomorrow, 00:57
Joined
Jan 19, 2010
Messages
409
Hi All you experts!

I am trying to import to Access few XML files, containing, roughly, products, ingredients, and prices. The products and ingredients data are linked by products Primary key - a number up to 18 digits long. In the XSD file, the field is declared as an Integer type.

While in products table the field is converted to String, and all data seems to be imported, in ingredients table the field stays a Long, and large numbers are not imported.

Changing the field type in xsd to String still creates in the table a Long type field.

I tried to first create the field as a string type, then import:
Code:
[INDENT]App.NewCurrentDatabase FileNameMDB, acNewDatabaseFormatAccess2002
App.ImportXML FilePaths(i), acStructureOnly
App.CloseCurrentDatabase
Set dbs = OpenDatabase(FileNameMDB)
'   ChangeFieldType A sub I created, works fine
ChangeFieldType dbs, "ING", "ISID", dbText, 50 
dbs.Close: Set dbs = Nothing
App.OpenCurrentDatabase FileNameMDB
App.ImportXML FilePaths(i), acAppendData
App.CloseCurrentDatabase
[/INDENT]
some of the data (some up to 17 digits long) gets imported, some 45% of the data is found in the IMPORT ERRORS table, with error message (translated from Hebrew): The decimal field's precision is too small to accept the numerical value you were trying to add.

how would I Import the numbers as a String?
 

Ranman256

Well-known member
Local time
Today, 17:57
Joined
Apr 9, 2015
Messages
4,339
the target access table would have a field as text.
you can import a # field into a text field.
 

marlan

Registered User.
Local time
Tomorrow, 00:57
Joined
Jan 19, 2010
Messages
409
Thanks for your reply.

This line of code tackes care of that:
Code:
ChangeFieldType dbs, "ING", "ISID", dbText, 50
("ING" being the table name, and "ISID" being the field name)
changes field type to dbText, 50 Chars long. It runs after creating the table:
Code:
App.ImportXML FilePaths(i), acStructureOnly
and before inserting the data:
Code:
App.ImportXML FilePaths(i), acAppendData

would anybody how exactly ImportXML works?
 

jdraw

Super Moderator
Staff member
Local time
Today, 17:57
Joined
Jan 23, 2006
Messages
15,379
In order to get more focused help, I think you could post (zip format) a small xml file with a few records to be imported, and
a copy of your database showing all of the code and subroutines/functions that you have currently.

As ranman has advised
a number up to 18 digits long
is not going to be an integer in Access.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 05:57
Joined
May 7, 2009
Messages
19,229
ImportXml on works when you exportxml it. It cannot correctly interpret othe xml file. Rhe best way is to create a udf parser.
 

marlan

Registered User.
Local time
Tomorrow, 00:57
Joined
Jan 19, 2010
Messages
409
In order to get more focused help, I think you could post (zip format) a small xml file with a few records to be imported, and
a copy of your database showing all of the code and subroutines/functions that you have currently..
I am attaching some sample data and relevant process.

As ranman has advised is not going to be an integer in Access.
I would like it to be text, and contain all data.

TIA!
 
Last edited:

marlan

Registered User.
Local time
Tomorrow, 00:57
Joined
Jan 19, 2010
Messages
409
ImportXml on works when you exportxml it. It cannot correctly interpret othe xml file. Rhe best way is to create a udf parser.

Would you know how Access decides if to create a numeric or text field?
 

Users who are viewing this thread

Top Bottom