Results 1 to 5 of 5

Thread: Create a linked table in Access via VB code?

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2000
    Posts
    1,091
    Is it possible to create a linked table in Access via
    VB code rather than doing it from within Access?

    For example, I want to create a linked table in an
    Access db named db1.mdb. The text file will be named data.txt
    and reside in c:\.

    Please assume that Access will not be installed on the end user machine so I do not want to use Access objects..

    Any help or guidance would be appreciated..

    Dan

  2. #2
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    Try this:

    Code:
       Dim db As Database
       Dim td As TableDef
    
       On Error Goto ErrHnd
    
       Set db = Workspaces(0).OpenDatabase("c:\db1.mdb")
    
       set td = db.CreateTableDef("TextFileTable")
       td.Connect = "c:\YourDirectory\"
       td.SourceTable = "data.txt"
       db.TableDefs.Append td
    
       Exit Sub
    
    ErrHnd:
       MsgBox Err.Description

    When you distribute your application, you will need to distribute DAO library as well.

    Regards,

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2000
    Posts
    1,091
    Thanks, works great! But, is there a way to do it in ADO? I just want to minimize the amount of code to distribute and I use ADO for everything else.. I tried in ADO but there doesn't seem to be a TableDef feature...

    Any ideas would be great!

    Dan

  4. #4
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2000
    Posts
    1,091
    Wow, why does it look so much more complicated than using DAO? Also, I'm not sure what ADOX is but I wanted to use ADO. Is it one and the same? If not, is there an ADO example that you can provide me?

    Thanks,

    Dan

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width