Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 47
Default Importing Access Tables

I am trying to import a table from an access database that is saved on my c
drive and import it into a worksheet.....I keep getting a type mismatch error
when I try to set the recordset.....Got any suggestions?....Here is the code
I'm using.....

Dim DBFullName As String
Dim TableName As String
Dim FieldName As String
Dim TargetRange As Range
Dim db As Database
Dim rs As Recordset
Dim intColIndex As Integer

DBFullName = "C:\Documents and Settings\Junior\My Documents\Consumer
Loans.mdb"
TableName = "tbl_CLC"


Set TargetRange = Excel.Application.Worksheets("CLC").Range("A1")
Set db = OpenDatabase(DBFullName)
Set rs = db.OpenRecordset(TableName, dbOpenTable) ' all records
For intColIndex = 0 To rs.Fields.Count - 1
TargetRange.Offset(0, intColIndex).Value = rs.Fields(intColIndex).Name
Next
' write recordset
TargetRange.Offset(1, 0).CopyFromRecordset rs
Set rs = Nothing
db.Close
Set db = Nothing


--
Thanks in advance....
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 318
Default Importing Access Tables

Hi Matthew,
Just check if you have references set to both the ADO as well as the DAO. If
you do and if ADO is ahead of the DAO in the references listed then you could
get this error. You can easily correct it by declaring rs as DAO.Recordset.
Hope this helps.


"Matthew" wrote:

I am trying to import a table from an access database that is saved on my c
drive and import it into a worksheet.....I keep getting a type mismatch error
when I try to set the recordset.....Got any suggestions?....Here is the code
I'm using.....

Dim DBFullName As String
Dim TableName As String
Dim FieldName As String
Dim TargetRange As Range
Dim db As Database
Dim rs As Recordset
Dim intColIndex As Integer

DBFullName = "C:\Documents and Settings\Junior\My Documents\Consumer
Loans.mdb"
TableName = "tbl_CLC"


Set TargetRange = Excel.Application.Worksheets("CLC").Range("A1")
Set db = OpenDatabase(DBFullName)
Set rs = db.OpenRecordset(TableName, dbOpenTable) ' all records
For intColIndex = 0 To rs.Fields.Count - 1
TargetRange.Offset(0, intColIndex).Value = rs.Fields(intColIndex).Name
Next
' write recordset
TargetRange.Offset(1, 0).CopyFromRecordset rs
Set rs = Nothing
db.Close
Set db = Nothing


--
Thanks in advance....

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 47
Default Importing Access Tables

Hey Thanks it worked.....Thats all that was wrong....I declared it a
DAO.Recordset and it worked....

"Alok" wrote:

Hi Matthew,
Just check if you have references set to both the ADO as well as the DAO. If
you do and if ADO is ahead of the DAO in the references listed then you could
get this error. You can easily correct it by declaring rs as DAO.Recordset.
Hope this helps.


"Matthew" wrote:

I am trying to import a table from an access database that is saved on my c
drive and import it into a worksheet.....I keep getting a type mismatch error
when I try to set the recordset.....Got any suggestions?....Here is the code
I'm using.....

Dim DBFullName As String
Dim TableName As String
Dim FieldName As String
Dim TargetRange As Range
Dim db As Database
Dim rs As Recordset
Dim intColIndex As Integer

DBFullName = "C:\Documents and Settings\Junior\My Documents\Consumer
Loans.mdb"
TableName = "tbl_CLC"


Set TargetRange = Excel.Application.Worksheets("CLC").Range("A1")
Set db = OpenDatabase(DBFullName)
Set rs = db.OpenRecordset(TableName, dbOpenTable) ' all records
For intColIndex = 0 To rs.Fields.Count - 1
TargetRange.Offset(0, intColIndex).Value = rs.Fields(intColIndex).Name
Next
' write recordset
TargetRange.Offset(1, 0).CopyFromRecordset rs
Set rs = Nothing
db.Close
Set db = Nothing


--
Thanks in advance....

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 252
Default Importing Access Tables

do you need to declare "dbOpenTable"

Do you have Option Explicit at the top of your module?

"Matthew" wrote:

I am trying to import a table from an access database that is saved on my c
drive and import it into a worksheet.....I keep getting a type mismatch error
when I try to set the recordset.....Got any suggestions?....Here is the code
I'm using.....

Dim DBFullName As String
Dim TableName As String
Dim FieldName As String
Dim TargetRange As Range
Dim db As Database
Dim rs As Recordset
Dim intColIndex As Integer

DBFullName = "C:\Documents and Settings\Junior\My Documents\Consumer
Loans.mdb"
TableName = "tbl_CLC"


Set TargetRange = Excel.Application.Worksheets("CLC").Range("A1")
Set db = OpenDatabase(DBFullName)
Set rs = db.OpenRecordset(TableName, dbOpenTable) ' all records
For intColIndex = 0 To rs.Fields.Count - 1
TargetRange.Offset(0, intColIndex).Value = rs.Fields(intColIndex).Name
Next
' write recordset
TargetRange.Offset(1, 0).CopyFromRecordset rs
Set rs = Nothing
db.Close
Set db = Nothing


--
Thanks in advance....

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Removing Data Tables formed from importing data from Access Andrea Jones Excel Discussion (Misc queries) 0 April 10th 08 12:01 PM
Importing from Access sfleck Excel Worksheet Functions 2 January 31st 08 12:35 AM
Importing from Access Richard Excel Discussion (Misc queries) 1 October 19th 07 02:05 PM
Importing Tables from Access into Excel using Macros or VBA CLamar Excel Discussion (Misc queries) 4 May 23rd 06 09:23 PM
Importing Access tables to an Excel worksheet. Narwe Excel Programming 0 September 13th 04 05:35 AM


All times are GMT +1. The time now is 03:52 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"