Access

DAO - Question 9

 

 

 

How do I export to text?

[Access]   [ADO]   [DAO]

;
;   Question 9 -- How do I export to text?
;
;   First we need to setup some variables for the export...
   dpath = DirScript()
   spec = "DAO-Export.txt"
   tfile = StrCat(dpath, spec)
;
;   Next we delete the file if it exists, because DAO won't overwrite it...
   If FileExist(tfile) Then FileDelete(tfile)
;
   dbname = StrCat(dpath, "Winbatch-Access-Tutorial.mdb")
   dao = ObjectCreate("DAO.DBEngine.36")
   ws = dao.CreateWorkspace("JetWorkspace", "admin", "")
   db = ws.OpenDatabase(dbname)
;
;   What this does is select the records from the Employees table into a
;   "text table" on the drive. By specifying the output table's type, it's
;   path and it's name, Access will export it to text for us...
   sqlstr = `SELECT * INTO [Text;DATABASE=%dpath%].[%spec%] FROM [Employees]`
;
;   Execute the command...
   db.execute(sqlstr)
;
;   Zero out the OLE handles...
   db = 0
   ws = 0
   dao = 0
;
;   If you check the folder the script resides in, you'll see a file called
;   "Schema.ini" which contains information on the export. You can look at
;   this closely then create your own specifications for exports if you want
;   or let Access handle the housekeeping as we did. The default is a CSV
;   file, but you may need other types. You can use the web to find other
;   methods of doing exports with DAO. The data is now usable by Winbatch's
;   ArrayFileGetCSV() function, or for importing into other programs.