
Problems using VBA to link or DAO to import Excel file into Access97
Hi,
I am trying to create an process that programatically links in an Excel
spreadsheet or is able to open it using DAO. I have been able to do it for
dBASE files, but for Excel it just doesn't want to work. Check out what I
have tried and let me know if you have any ideas. Thanks!
I can link the table manually but when trying to execute the following code
I get error 3051: The Microsoft Jet database engine cannot open the file
'C:\QDSRsp\Data' It is already opened exclusively by another user, or you
need permission to view its data. (There is no password on the XLS file and
there aren't any other processes that have it open.)
Dim db As DATABASE, tdf As TableDef
Set db = CurrentDb
Set tdf = db.CreateTableDef("Test")
tdf.Connect = "Excel 5.0;Database=C:\QDSRsp\Data"
tdf.SourceTableName = "Test.xls"
db.TableDefs.Append tdf
Set dbs = Nothing
I have also tried open the XLS file using DAO with the same result. (With
the dBASE file this also works fine.)
Set dbImport = DBEngine.Workspaces(0).OpenDatabase("C:\QDSRsp\Data,
False, True, "Excel 5.0")
Set rsSource = dbImport.OpenRecordset("Test.xls", dbOpenSnapshot)
I even tried a SQL statement. (Once again, this didn't work for Excel but
worked perfectly for dBASE)
SELECT * FROM Test.xls IN "C:\QDSRsp\Data" "Excel5.0;"
Yes I have tried the transferspread method and it works fine...but what's
going on with the other methods?
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel5,
"tblTempDigitalPrinting","C:\QDSRsp\Data\Test.xls", True
--
Doug Rhoten
Quality Data Systems