Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

access 97 link to excel, recordset problem

Status
Not open for further replies.

reta

Technical User
Dec 23, 2004
51
AU
i have a db that is linked to an excel spreadsheet, but when i add a recordset that links to the spreadsheet it gives me an error "type mismatch"
CODE:
Dim dbs As Database
Dim tdf As TableDef
Dim rs1 As ADODB.Recordset

' Open the Microsoft Access database.
Set dbs = CurrentDb

' Create a TableDef object.
Set tdf = dbs.CreateTableDef("Freight Rates")

' Set the connection string to specify the source database type and the
' path to the workbook that contains the data you want to link.
tdf.Connect = "Excel 5.0;DATABASE=G:\Honda DB Analyser\FreightRates.xls"

' Set the SourceTableName property to the worksheet you want to access.
tdf.SourceTableName = "Sheet1$"

' Append the TableDef object to the TableDefs collection to create a link.
dbs.TableDefs.Append tdf

' Create a Recordset object from the linked Microsoft Excel worksheet.
Set rs1 = dbs.OpenRecordset("Freight Rates")

Also i would like to know how to remove the link.
Thanks
Reta
 
Replace this:
Dim rs1 As ADODB.Recordset
By this:
Dim rs1 As DAO.Recordset

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top