AccessADO - Question 9 |
|
; ; Question 9 -- How do I export to text? ; ; First we need to setup some variables for the export... dpath = DirScript() spec = "ADO-Export.txt" tfile = StrCat(dpath, spec) ; ; Next we delete the file if it exists, because ADO won't overwrite it... If FileExist(tfile) Then FileDelete(tfile) ; dbname = StrCat(dpath, "Winbatch-Access-Tutorial.mdb") connStr = "Provider=MicroSoft.Jet.OLEDB.4.0; Data Source=%dbname%" adoConn = ObjectCreate("ADODB.Connection") adoConn.open(connStr) ; ; 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... adoConn.execute(sqlstr) ; ; Zero out the OLE handle... adoConn = 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 ADO. The data is now usable by Winbatch's ; ArrayFileGetCSV() function, or for importing into other programs.