Import text file fixed

  • Thread starter Thread starter tkdudine
  • Start date Start date
T

tkdudine

I usually connect (link) data from txt files into Access DB using the
external file as a linked table with some code like this:

tbl.Connect = "Text;DATABASE=" & sPath & ";TABLE=" & file &
";HDR=No;FMT=FixedLenght"
tbl.SourceTableName = file
tbl.Name = Left(file, InStr(1, file, ".") - 1)
db.TableDefs.Append tbl
db.TableDefs.Refresh

but it don't works well if in the linked file there is a double quote.
Have you got any suggestion? Can I create a simple function that replace
chr(34) with another character in the external file before linking or at last
stops the link operation if finds it?

A.
 
I usually connect (link) data from txt files into Access DB using the
external file as a linked table with some code like this:

            tbl.Connect = "Text;DATABASE=" & sPath & ";TABLE=" & file &
";HDR=No;FMT=FixedLenght"
            tbl.SourceTableName = file
            tbl.Name = Left(file, InStr(1, file, ".") - 1)
            db.TableDefs.Append tbl
            db.TableDefs.Refresh

but it don't works well if in the linked file there is a double quote.
Have you got any suggestion? Can I create a simple function that replace
chr(34) with another character in the external file before linking or at last
stops the link operation if finds it?

A.
assuming you can get the filename from your code, you could just use
Replace() to remove the characters you don't want and then Rename to
rename the file. You can use a FileSystemObject, but those are dodgy
because they can open up your computer to all kinds of abuse. Once
the file is renamed, you would append that with the new name.
 
assuming you can get the filename from your code, you could just use
Replace() to remove the characters you don't want and then Rename to
rename the file. You can use a FileSystemObject, but those are dodgy
because they can open up your computer to all kinds of abuse. Once
the file is renamed, you would append that with the new name.

Of course it works! Just a read-write code ...
Thanks

A.
 
Back
Top