Solved

Creating a Linked Table (Linked to TEXT)

Posted on 1998-01-11
2
344 Views
Last Modified: 2008-08-07
I am trying to write code that creates a linked table to a text file.  I have already created the code that properly creates the MSysIMexSpecs, and MSYSIMEXColumns so that my import specs. can be used.  When I use the following code
sub tmp()
Dim tbldef As New TableDef
Dim dbs As Database
Set dbs = wks.OpenDatabase("r:\test.mdb")
tbldef.Attributes = dbAttachedTable
tbldef.Connect = "Text;DSN=ALLETA Link specification;FMT=Delimited;HDR=NO;IMEX=2;DATABASE=C:\Webpages\Database"
tbldef.Name = "ALLETA_LINK"
tbldef.SourceTableName = "ALLETA.TXT"
dbs.TableDefs.Append tbldef
end sub
   
I get an error on the attributes line. What is the proper way to do this.  I am trying to duplicate a database that I created in Access 97, in source code, so that the program can create it at install time.  
Thanks
0
Comment
Question by:redbaron082997
2 Comments
 
LVL 6

Accepted Solution

by:
anthonyc earned 200 total points
ID: 1450393
This is what I would do:

public sub LinkTextTable
  dim db as database
  dim tblNew as tabledef

  set db = workspaces(0).opendatabase("r:\test.mdb")
.CreateTableDef([name[, attributes[, source[, connect]]]])
  set tblNew = db.createtabledef("ALLETA_LINK", dbAttachedTable, "ALLETA.TXT", "Text;DSN=ALLETA Link specification;FMT=Delimited;HDR=NO;IMEX=2;DATABASE=C:\Webpages\Database"
  db.tabledefs.append tblNew
end sub

Why is this different?  You are telling the actual database to create the new table.  This is how I do it.  I usually link dBase tables, but its all the same.
0
 
LVL 1

Author Comment

by:redbaron082997
ID: 1450394
Yes, but it doesn't find the Link specification.  It gives that error every time, even though I checked the tables and they are there correctly.  I assumed that for DSN=blah, that it would look in the MSYSIMEXSpecs, and Columns tables. That is what the problem has been. The syntax will work several different ways,but the error is always the same.  I could not find any documentation at all on the subject.  If I omit the DSN=blah then I get the attached table, and the field names and types are all automatic, and *wrong*.

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now