Solved

Creating a Linked Table (Linked to TEXT)

Posted on 1998-01-11
2
343 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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

708 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

14 Experts available now in Live!

Get 1:1 Help Now