Import text file fixed

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.
 
P

pietlinden

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.
 
T

tkdudine

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top