I'm trying to import a txt file into my Microsoft Access database but data is being treated as numeric instead of text.
My source file (named sourcefile.txt) is like this:
00120230200001083300091959212311
00120230200001220500220559212311
00120230200240082700083259212311
00120230200240220600224059212311
00120230205001224100234959212311
00120230300001190700193359212311
Around 80.000 rows of data, no fields or delimitation, all rows same length (32 chars). I want to import that data to a table named T_RAW_SWD with just 2 fields:
swdis the first field and has been set as text with 255 limit charactersid_swdis autonumeric and is the primay key
So the idea is to import all those data rows as text into field swd. I've tried just reading data using a query like this:
SELECT F1 AS swd FROM [Text;FMT=Delimited;HDR=No;Database=C:\Temp;IMEX=1].filesource.txt;
This code loads the data but as number, not text. I thought using IMEX=1 would make the trick but no. Here's the output:
Desired output:
I've read some sources but could not figure out a solution. Also, I've tagged the question with VBA because tried with different macros based on some sources like these ones:
excel import text file using vba in access
How to read txt files and import them into access table
VBA Code - Import a text file into an Access table - With Condition
Changing connection string in Excel messes up column data types
DoCmd.TransferText method (Access)
ImportExportSpecification object (Access)
The differents codes I've tested import the data also as numeric. I've managed to load data into queries or tables but as numeric always. I'm totally stuck about what to do to read data as text so i don't lose any info.
If I manually import the data with the wizard it works properly, but there are several files and this task will be daily so I'm trying to make it faster with SQL code invoked from VBA o VBA itself.
Also tried first creating manually with the wizard an import routine and call it from DoCom.TransferText using acImportFixed with no success.
Any ideas of what I'm doing wrong here? I got no errors on importing the data trough code, but i need it as text, not numeric.
By the way, I'm working on Microsoft Access 2007 and Windows 10, just in case.
Thanks in advance.




