WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

OLE with Excel
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Access OLE Query export to Excel

Keywords: 	 Access OLE Query export to Excel 

Question:

I am trying to figure out how to export my Query results to an Excel spreadsheet using Access OLE. I used the tech db and got to the point where I can see the standard Query results using the code below. I need suggestions for the export to Excel?? I am using Office XP. All of this worked with sendkeys in Office 2000 but stopped working when I transferred to Office XP.
AccessDB = ObjectOpen("Access.Application")
ADB = AccessDB.Application
; make sure use full db path/name
ADB.OpenCurrentDatabase ("c:\Aerostd\ieee98.mdb")
ADB.Visible = @true
ADB.UserControl = @true
ADBCmd = ADB.docmd
ADBCmd.OpenQuery("PapersAndAuthors")
ADB.closecurrentDatabase
ADB.Quit

;' Release the object variable
ObjectClose(AccessDB

Answer:

This works:
; Create xl spread sheet from downloaded access database
xlFilename = "C:\Aerostd\PapersAndAuthors.xls"
acQuery = "PapersAndAuthors"
if Fileexist(xlFilename) then filedelete(xlfilename) ; Delete old sheet
AccessDB = ObjectOpen("Access.Application") ; OLE XP Version
ADB = AccessDB.Application ; Open Access
ADB.OpenCurrentDatabase ("c:\Aerostd\ieee98.mdb") ; Open DB
; ADB.Visible = @true ; Make access visible
ADBCmd = ADB.docmd ;Create OLE command first part
ADBCmd.TransferSpreadsheet(1, 8, acQuery, xlFilename, @True) ; Export Query to Spreadsheet
objectClose(ADB) ; Close oLE objects
objectClose(ADBCmd)
ObjectClose(AccessDB) 

Article ID:   W15622
File Created: 2003:05:13:11:29:18
Last Updated: 2003:05:13:11:29:18