B
Balex
Hi,
I am trying to link an Excel sheet as a table in Access through code, and I
stumble whatever I do on the database.TableDefs.Append <LinkedObject>
statement.
Situation is the following:
- there are a number of Excel files in a given directory
- the user gets a list of these in a combo box and clicks (chooses) one
- the code tries to add this Excel sheet as a linked table, and fails...
For the code, I have used an example in the Access help nearly "as is". It
is given as an example of the "Connect and SourceTableName Properties".
Basically what it does is calling a subroutine that has 4 arguments:
- database where the table is going (is = CurrentDB()); called dbsTemp in
the code
- a table name which is used in an OpenRecordset (which I don't reach
anyway, fails before); called strTable; I've put the name I'd like for the
table in the DB in that variable
- a strConnect string, which in my case is a db type (Excel 5.0) and pretty
long path and file name labelled as DATABASE:
Excel 5.0;DATABASE=S:\Securities\Domes&Bonds\WA8R\Projekte\EQ
Investor\makro\KIGOAL optimisation\VBA - Access -
Excel\Trades\2006-05-22_EQISecTrades.xls
- a strSourceTable string, which role I don't quite understand, but which
seems to be the problem; I've put various values in there, to no avail. The
last one is the sheet name within the Excel workbook, "Sheet0"
The routine does this:
Set tdfLinked = dbsTemp.CreateTableDef(strTable)
tdfLinked.Connect = strConnect
tdfLinked.SourceTableName = strSourceTable
dbsTemp.TableDefs.Append tdfLinked
the last statement is the one that is failing, with a runtime error 3011,
the DB engine "could not find the object 'Sheet0'. Make sure the object
exists and that you spell its name and the path name correctly". In the
Access Help example, this variable is jus a plain name which seems to be just
something that one can choose freely. As I said, whatever I set in there, it
doesn't work.
Can anyone tell me where the whole thing is going pear-shaped ?
I'd be grateful for any help, hints, and alternative methods to link by code
an Excel table into an mdb.
Regards
Balex
I am trying to link an Excel sheet as a table in Access through code, and I
stumble whatever I do on the database.TableDefs.Append <LinkedObject>
statement.
Situation is the following:
- there are a number of Excel files in a given directory
- the user gets a list of these in a combo box and clicks (chooses) one
- the code tries to add this Excel sheet as a linked table, and fails...
For the code, I have used an example in the Access help nearly "as is". It
is given as an example of the "Connect and SourceTableName Properties".
Basically what it does is calling a subroutine that has 4 arguments:
- database where the table is going (is = CurrentDB()); called dbsTemp in
the code
- a table name which is used in an OpenRecordset (which I don't reach
anyway, fails before); called strTable; I've put the name I'd like for the
table in the DB in that variable
- a strConnect string, which in my case is a db type (Excel 5.0) and pretty
long path and file name labelled as DATABASE:
Excel 5.0;DATABASE=S:\Securities\Domes&Bonds\WA8R\Projekte\EQ
Investor\makro\KIGOAL optimisation\VBA - Access -
Excel\Trades\2006-05-22_EQISecTrades.xls
- a strSourceTable string, which role I don't quite understand, but which
seems to be the problem; I've put various values in there, to no avail. The
last one is the sheet name within the Excel workbook, "Sheet0"
The routine does this:
Set tdfLinked = dbsTemp.CreateTableDef(strTable)
tdfLinked.Connect = strConnect
tdfLinked.SourceTableName = strSourceTable
dbsTemp.TableDefs.Append tdfLinked
the last statement is the one that is failing, with a runtime error 3011,
the DB engine "could not find the object 'Sheet0'. Make sure the object
exists and that you spell its name and the path name correctly". In the
Access Help example, this variable is jus a plain name which seems to be just
something that one can choose freely. As I said, whatever I set in there, it
doesn't work.
Can anyone tell me where the whole thing is going pear-shaped ?
I'd be grateful for any help, hints, and alternative methods to link by code
an Excel table into an mdb.
Regards
Balex