Results 1 to 8 of 8

Thread: attaching a text file to a database

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 1999
    Location
    UK
    Posts
    300

    Post

    I am trying a small example of attaching a textfile to the biblio.mdb, I have set up a empty table called mytable with the fields
    name (text)
    age (text)
    color (text)

    I have also set up a .dat file like this
    "name","age","color"
    "mark","12","red"
    "karen","39","blue"
    "paul","33","green"
    "cee-jay","87","yellow"
    "brandon","35","pink"

    I want to attach this text file into the database which I presume has a tabledef already (as I have made it in visdata)

    I have tried this code to do the task but it won't work, any help would be appreciated. Could you also explain any code submitted in layman's terms as I am relatively new to db programming!.

    Option Explicit
    Dim mydb As Database
    Dim myrs As Recordset


    Private Sub Command1_Click()
    Dim tdf As TableDef

    On Error GoTo errorhandler
    Set tdf = mydb.CreateTableDef("mytable")
    tdf.Connect = "c:\begDB\biblio.mdb"
    tdf.SourceTableName = "c:\Mark\attachfile.dat"
    mydb.TableDefs.Delete ("mytable")
    mydb.TableDefs.Append tdf
    Exit Sub


    errorhandler:
    MsgBox " crashed and burned baby!"
    MsgBox = MsgBox & Err.Number
    Exit Sub
    End Sub

    Private Sub Form_Load()
    Set mydb = OpenDatabase("c:\begDB\biblio.mdb")

    End Sub

    Thanks again ! > locutus

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

    Post

    Try this:

    Code:
       Dim db As Database
       Dim td As TableDef
    
       On Error Goto ErrHnd
    
       Set db = Workspaces(0).OpenDatabase("c:\begDB\biblio.mdb")
    
       set td = db.CreateTableDef("MyTable")
       td.Connect = "c:\Mark\"
       td.SourceTable = "attachfile.dat"
       db.TableDefs.Append td
    
       Exit Sub
    
    ErrHnd:
       MsgBox Err.Description

    Regards,

    ------------------

    Serge

    Software Developer
    [email protected]
    [email protected]



  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 1999
    Location
    UK
    Posts
    300

    Post

    Thanks for replying to my query Serge !
    When I try the code above I get the err
    3170 Couldn't find installable ISAM
    I know this is Index Sequential Access Method
    but don't understand whats going on :-(
    please could you spare a minute to help

    Thanks > locutus

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

    Post

    Do you have MS Access installed? If you do, then you should have that ISAM driver installed. To check if the driver is installed do the following:

    1. Open Control Panel.
    2. Select ODBC32 (or ODBC Data Sources) and double click on it.
    3. Click on Add button

    If you see something like this:

    Microsoft Text Driver (*.txt;*.csv) then you have it installed. If you don't then you can get this driver from Microsoft's Web site. Unfortunately, I can't give you the exact link, but I think if you search their site, you can find it.


    Regards,

    ------------------

    Serge

    Software Developer
    [email protected]
    [email protected]




    [This message has been edited by Serge (edited 09-22-1999).]

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 1999
    Location
    UK
    Posts
    300

    Post

    Thanks again !
    I did like you said and do have both the access driver and text driver installed.

    This was meant to be a small test program to try out attaching text files to a pre defined, empty database. Do you have any further advice ?
    Any help is much appreciated :-)

    > locutus

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

    Post

    Then the code above should work. I've checked the MSDN library and it doesn't even matter what version of DAO you use, the line:

    td.Connect = "c:\Mark\"

    should not give you a problem.

    The only thing that I can think of is to try to reinstall Access.

    Hope this will help.
    Regards,


    ------------------

    Serge

    Software Developer
    [email protected]
    [email protected]



  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 1999
    Location
    UK
    Posts
    300

    Post

    In case you read this Serge I found what was missing.It should read

    tdf.connect ="text;database =c:\Mark;"

    when this bit was put in ie "text;database="
    it worked fine !.
    Ahhh you live and learn ( said in Homer type voice)
    anyhow thanks for the pointers ->

    locutus

  8. #8
    Member
    Join Date
    Apr 1999
    Location
    Kirkland, WA, USA
    Posts
    40

    Post

    Minor thing Serge, this linking does not use the ODBC drivers, it uses only the Jet ISAM support drivers, which are MStextXX.dll for text/html, MSxbseXX.dll for dBase&foxpro, etc.

    (When you deply, make sure the ISAM dlls that you need to sue are packaged with your setup)



    ------------------
    http://www.smithvoice.com/vbfun.htm

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