Access

Access - 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 = "Access-Export.txt"    tfile = StrCat(dpath, spec) ; ;   Next we delete the file if it exists, because Access won't overwrite it...    If FileExist(tfile) Then FileDelete(tfile) ;    dbname = StrCat(dpath, "Winbatch-Access-Tutorial.mdb")    Access = ObjectCreate("Access.Application")    Access.OpenCurrentDatabase(dbname)    Access.Visible = @TRUE    db = Access.currentdb ; ;   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) ; ;   Quit Access and zero out the OLE handles...    Access.quit    db = 0    Access = 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 Access. The data is now usable by Winbatch's ;   ArrayFileGetCSV() function, or for importing into other programs.