Access 

ADO - Question 10

 

 

 

How do I import text data?

[Access]   [ADO]   [DAO]

;
;    Question 10 -- How do I import text data?
; ;   First we need to setup some variables...    dpath = DirScript()    spec = "ADO-Export.txt"    tfile = StrCat(dpath, spec)    dbname = StrCat(dpath, "Winbatch-Access-Tutorial.mdb")    aTable = "NewTable-ADO"    sqlstr = `SELECT * INTO [%aTable%] IN '%dbname%' FROM [%spec%]` ;    adoConn = ObjectCreate("ADODB.Connection")    connStr = "Driver={Microsoft Text Driver (*.txt; *.csv)}; DEFAULTDIR=%dpath%;"    adoConn.open(connStr)    adoConn.execute(sqlstr) ;    adoConn.close    adoConn = 0 ; ;   Now open up Access and take a peek at the new table and it's data. ; ;   Note: you'll get an error if the table already exists, so you can do two things, ;   either delete the table by hand, or write a script to do so. Another option would ;   be to use a different SQL statement, such as "INSERT INTO..." instead of "SELECT INTO..." ;   this will append data, so be careful, you don't accidentally duplicate data unneccesarily.