AccessAccess - Question 10 |
|
; ; Question 10 -- How do I import text data?
; ; First we need to setup some variables... dpath = DirScript() spec = "Access-Export.txt" dTable = "NewTable-Access" ; tfile = StrCat(dpath, spec) dbname = StrCat(dpath, "Winbatch-Access-Tutorial.mdb") ; ; Now open the Access application... Access = ObjectCreate("Access.Application") ; ; specify the input file's type, path and name... ; ifile = "Text;DATABASE=%dpath%;table=%spec%" ; ; Open up the input file as though it were a database... ; db = Access.Application.DBEngine.OpenDatabase(dpath,@FALSE,@FALSE,ifile) sqlstr = `SELECT * INTO [%dTable%] IN '%dbname%' FROM [%spec%]` db.execute(sqlstr) ; db = 0 Access.quit Access = 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.