Link to text file in code

T

Tomk

I'm relinking a set of tables to Access 2000. Most of the links are other
databse tables & excel workbooks which all work fine. My problem is with a
fixed field length text file. The code below runs without errors and shows
the linked text file in the tables list however it does not function
correctly. I'm wondering what the DNS=MyTextFile Link Specification2 refers
to? There is no such DSN in my registry. I just copied the code from
another example and the MSysObjects connect field after manually creating
the link. The Database portion of strConn is the path to the text file.
When I make the link manually the wizard does not correctly delinieate the
fields, I must define them manully. This seems like that is what is missing
in my code unless the DSN should handles this but then I can't find that
either.


strConn = "Text;DSN=MyTextFile Link
Specification2;FMT=Fixed;HDR=NO;IMEX=2;CharacterSet=437;DATABASE=" &
!Database & ";"
strTblName = !LocalTableName

If (DoesTblExist(strTblName) = False) Then
Set tbl = db.CreateTableDef(strTblName)
tbl.Connect = strConn
tbl.SourceTableName = strTblName & ".txt"
db.TableDefs.Append tbl
Else
Set tbl = db.TableDefs(strTblName)
tbl.Connect = strConn
tbl.RefreshLink
End If
 

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